How to make an HTTP call to YouTube Analytics API? - google-api

I want to get information about top keywords driving traffic to my own YouTube channel over the past 7 days. In order to do that, I followed all of the instructions. Then I generated a new access_token for my account
When I make such a request:
curl -X GET \
'https://youtubeanalytics.googleapis.com/v2/reports?dimensions=insightTrafficSourceDetail;7DayTotals&metrics=views&filters=insightTrafficSourceType==YT_SEARCH;channel==MINE&maxResults=10&sort=-views' \
-H 'Authorization: Bearer access_token'
I receive back an error:
"error": {
"code": 400,
"message": "Required",
"errors": [
{
"message": "Required",
"domain": "global",
"reason": "required"
}
]
}
}
What I do wrong when construct this kind of request?

"error": {
"code": 400,
"message": "Required",
"errors": [
{
"message": "Required",
"domain": "global",
"reason": "required"
}
]
}
Is basically a really bad error message telling that you are missing a required field.
If you check the Documentation you will notice that startdate and enddate are required fields. You have forgotten to add them to your request
Also when you get that far you separate dimensions and metrics with a , not a ;

So the problem was in query params, which I set incorrectly. Here is how the URL should be formed in order to get the data from the question:
https://youtubeanalytics.googleapis.com/v2/reports?dimensions=insightTrafficSourceDetail&metrics=views&filters=insightTrafficSourceType==YT_SEARCH&maxResults=10&sort=-views&startDate=2019-07-03&endDate=2019-07-10&ids=channel==MINE

Related

Google Civic Information API `/voterInfoQuery` route returning 400

When testing the API at this site (https://developers.google.com/civic-information/docs/v2/elections/voterInfoQuery) I only receive a 400 response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Election unknown"
}
],
"code": 400,
"message": "Election unknown"
}
}
is this API still supported?
Yes, the API is still supported. Did you resolve the issue?
If not, make sure you're putting in a valid number for the electionId (2000 should work).

Google Plus Domains Api insert Activities in error

I try to create activity through the form 'Google+ Domains API v1' with 'plusDomains.activities.insert'
I use scopes :
https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/auth/plus.me
https://www.googleapis.com/auth/plus.stream.write
Request is : https://www.googleapis.com/plusDomains/v1/people/me/activities?preview=true&fields=access&key={YOUR_API_KEY}
parameters :
{
"object": {
"originalContent": "Test"
},
"access": {
"items": [
{
"type": "domain"
}
],
"domainRestricted": true
}
}
but I have the following error :
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
and I have this message :
You do not have permission to execute this method.
This API call requires OAUTH2.0 authorization not an API key. That's the reason you're getting the error.
It's clearly stated in Activities.insert:
"Requires authorization"
To prove this, give the Try-it a go. It uses OAuth2. Your request should work.

An error attempting to rename a Google Bucket object (Google bug?)

I try to rename an object in a bucket (below named BUCKET). I obtain an access token (XXX) and use it below. But it does not work. See the transcript:
$ curl -X POST -H "Authorization: Bearer XXX" \
"https://www.googleapis.com/upload/storage/v1/b/BUCKET/o/rdf.ads/rewriteTo/b/BUCKET/o/xxx"
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Unsupported content with type: application/octet-stream"
}
],
"code": 400,
"message": "Unsupported content with type: application/octet-stream"
}
}
I think it is a Google bug. Or why does it not work?!
You need to remove the "upload" prefix in that path (see the HTTP request documented at https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite)

Cant print the error message in console from object

I receive the following object error:
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
I'd like to call an action when the error code is 401 or message is "Invalid Credentials" but the following code does nothing and when I try do console.error("got something:", err["code"]); to log in the console it comes blank:
console.error("got something:", err["code"]);
if (err["code"]=="401") {
console.log("Found error: 401");
this.messageServ.presentMessage("auth_error");
}
return err;
Looks like your not access fields deep enough in your object graph
Try this:
err["error"]["code"]

Create and Share bucket in google cloud storage using google api's

i need to create and share a bucket in gcloud storage using google api's. but i got an error when am tring with postman(rest client).
Iam trying with
url
-------
https://www.googleapis.com/storage/v1/b?project=testproject
request body
------------
{
"name":"testbucketmanafnew"
}
i got an error
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
after iam created an access tocken using OAuth 2.0 Playground. And added to header
Authorization = ya29.VALUE_REDACTED
But i got error
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
what did i miss?
using Google api explorer, am able to call api's successfully
POST https://www.googleapis.com/storage/v1/b?project=testproject&key={YOUR_API_KEY}
{
"name": "testmanafcjbucketyy"
}
Authorization needs to be passed in the following format.
Authorization: Bearer [oauth2_token]
if you're using Postman the "Header" field becomes Authorization and the "Value" field becomes Bearer[WHITESPACE][oauth2_token]

Resources