Creating direct HTTP-request through YouTube Analytics API v2 to view the videos of the channel that were embedded on external sites - youtube

I am quite new in using Google APIs. So, the problem is that I am administrator of the YouTube channel (not the owner). And I would like to get the straffic sources that were embedded on external websites. So, I've created new project and formed a request through Google APIs Explorer. Here it is:
https://youtubeanalytics.googleapis.com/v2/reports?dimensions=insightTrafficSourceDetail&endDate=2018-12-12&filters=insightTrafficSourceType%3D%3DEXT_URL&ids=channel%3D%3D{MY_CHANNEL}&maxResults=25&metrics=views&sort=-views&startDate=2014-05-01&key={MY_API_KEY}
Here is the result:
200
- Show headers -
{
"kind": "youtubeAnalytics#resultTable",
"columnHeaders": [
{
"name": "insightTrafficSourceDetail",
"columnType": "DIMENSION",
"dataType": "STRING"
},
{
"name": "views",
"columnType": "METRIC",
"dataType": "INTEGER"
}
],
"rows": [
[
"vk.com",
2399
],
[
"unknown",
872
],
[
"yandex.ru",
23
]
But when I try to write the request into the browser address bar directly, it says:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"domain": "global",
"reason": "unauthorized"
}
],
"status": "UNAUTHENTICATED"
}
}
I pushed into the {API_KEY} field from here
But, unfortunately, the result is such as provided above. What am I doing wrong? Can you provide the step-by-step instruction to get the right HTTP-request for my aim, as I counld'nt find it? Thank you!

Related

Search mails using graph api

we are using microsoft graph api list and send emails. The new requirement is to search emails. When following URL is tried then we are getting errors. Can someone suggest if this is the right api to search mails messages? or what kind of permissions are missing?
URL : https://graph.microsoft.com/v1.0/search/query (documentation here)
Error using following request body : "Application permission is only supported for the following entity types:site, list, listItem, drive and driveItem."
{
"requests": [
{
"entityTypes": [
"message"
],
"query": {
"queryString": "hello"
},
"region": "NAM",
"from": 0,
"size": 25
}
]
}
Error returned::
"code": "System.UnauthorizedAccessException",
"message": "Application permission is only supported for the following entity types:site, list, listItem, drive and driveItem.",
"target": "",
"httpCode": 403
When tried to change the body to get list, as expected it did not return list, as we have only mail.readwrite permissions.
{
"requests": [
{
"entityTypes": [
"listItem"
],
"query": {
"queryString": "contoso"
},
"region": "NAM",
"sharePointOneDriveOptions": {
"includeContent": "privateContent,sharedContent"
}
}
]
}
Error Returned:
"code": "System.UnauthorizedAccessException",
"message": "Access to ListItem in Graph API requires the following permissions: Sites.Read.All or Sites.ReadWrite.All. However, the application only has the following permissions granted: Mail.ReadWrite, Mail.Read",
"target": "",
"httpCode": 403
As per the doc - Known limitation , You can access only the signed-in user’s own mailbox. Searching delegated mailboxes is not supported. try to write query to search your own message.
Hope this helps
Thanks

How to fix 403 error when creating GoogleFit datasource

I am using GoogleFit Rest API to create a nutrition data source so that I can subsequently store nutrition information. I have done this successfully on Android via the GoogleFit SDK, but because no such SDK is available on iOS, I resorted to using the REST APIs via the link above. When trying to create the data source I am returned the following error:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
and the POST request I am using is:
Endpoint: https://www.googleapis.com/fitness/v1/users/me/dataSources
Body:
{
"application": {
"detailsUrl": "https://strongfoundation.dev",
"name": "Strong Foundation",
"packageName": "com.coding.casa.Strong.Foundation",
"version": "1.0.1"
},
"dataStreamId": "raw:com.google.nutrition:com.coding.casa.Strong.Foundation:Apple:iPad Air (3rd generation):****",
"dataType": {
"name": "com.google.nutrition"
},
"device": {
"manufacturer": "Apple",
"model": "iPad Air (3rd generation)",
"type": "phone",
"uid": "*****",
"version": "15.7"
},
"name": "strong-foundation-food",
"type": "raw"
}
Has anyone seen this error and was able to resolve it? I have tried adding the API Key to the request, but that did not change the error, and I do have the Fitness API enabled on my project.
EDIT:
I am also supplying a Bearer token with the following authorized scopes
"https://www.googleapis.com/auth/fitness.activity.read",
"https://www.googleapis.com/auth/fitness.body.write",
"https://www.googleapis.com/auth/fitness.body.read",
"https://www.googleapis.com/auth/fitness.nutrition.read",
"https://www.googleapis.com/auth/fitness.nutrition.write",
You don't include the others details of the REST method call.
Importantly, HTTP 403 is Forbidden suggesting that you didn't include an Authorization header in your request with value Bearer {TOKEN} where {TOKEN} is an access token for an identity that has suitable scopes to access the API. See authorization
Although Swift is not one of Google's officially supported languages, Google has a Swift REST Client Generator for Google APIs and you should be able to use it to generate a Google client library for Swift for Google Fit.
Did some more playing around with the FitnessAPI (specifically creating data sources) and found the issues was with my request payload.
The payload that worked for me is as follows:
{
"application": {
"detailsUrl": "https://strongfoundation.dev",
"name": "Strong Foundation",
"version": "1.0.1"
},
"dataType": {
"name": "com.google.nutrition"
},
"device": {
"manufacturer": "Apple",
"model": "iPad Air (3rd generation)",
"type": "phone",
"uid": "****",
"version": "15.7"
},
"name": "strong-foundation-food",
"type": "raw"
}
The deltas from the original one are removed the following properties:
application.packageName
dataStreamId

I can't get this Google Sheets API Get request to work

I am trying to have a game to request data from the Google Sheets API, and I can't get the API Key to function properly. I can visit my API Link in the browser, and it tells me it is getting HTTP 400 (Bad Request) and Google additionally says it's a bad API Key, despite having JUST generated it. For reference my link looks like this: "https://sheets.googleapis.com/v4/spreadsheets/[SHEET_ID]?key=[API_KEY]/values", and the browser views this when using it:
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_INVALID",
"domain": "googleapis.com",
"metadata": {
"service": "sheets.googleapis.com"
}
}
]
}
}
I have absolutely no idea what is going wrong, I know the API key and Sheet ID are right (Directly copied each from their respective source).

Microsoft Graph - Accessing /me or /user/{id}/ endpoints using client_credentials flow - requested user is invalid

We're using the client_credentials flow to get access for our application to tenants environments. The application has the correct scopes, and we get an access token that is working for other endpoints like /users but when doing a request like the following we get error messages.
GET https://graph.microsoft.com/beta/me/findRooms
{
"error": {
"code": "ErrorInvalidUser",
"message": "The requested user '{userId}#{tenantId}' is invalid.",
"innerError": {
"request-id": "b72d26a3-d0ad-42eb-a3d3-35951cb42b3d",
"date": "2020-01-21T10:21:28"
}
}
}
I understand that there's no "me" when we're just an application, but how do we access these types of endpoints in that case? Do I have to have a user to act as, as well? That seems to me like it defeats the purpose of a daemon like this. Cannot find any clear documentation on this matter. On this page in the docs on the use a token section they even refer to a /me endpoint, which is incorrect in that case.
I've tried requesting the /users/{id}/findRooms endpoint with all different kinds of ID's I can find in the access token - none of them work.
Other people with the same issue, that have yet to resolve it.
1. Feedback area in docs
2. Github issue
Best regards,
Christopher
Using the /users/{user-id} is the only pattern that will work with client credentials. In your case, this should work, so maybe it's an issue with the id you are using.
To make sure I'm not giving you bad information, I just tested this with an app-only token from the client credentials flow. Parsing that token over at https://jwt.ms, I see the roles claim like so:
"roles": [
"User.Read.All"
]
If first did a GET /users?$select=displayname,id, and this user was included in the response:
{
"displayName": "Adele Vance",
"id": "3103c7b9-cfe6-4cd3-a696-f88909b9a609"
}
This is the id to use in your findRooms call. I did GET /users/3103c7b9-cfe6-4cd3-a696-f88909b9a609/findrooms and got the following response:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)",
"value": [
{
"name": "Conf Room Adams",
"address": "Adams#M365x330971.onmicrosoft.com"
},
{
"name": "Conf Room Baker",
"address": "Baker#M365x330971.onmicrosoft.com"
},
{
"name": "Conf Room Crystal",
"address": "Crystal#M365x330971.onmicrosoft.com"
},
{
"name": "Conf Room Hood",
"address": "Hood#M365x330971.onmicrosoft.com"
},
{
"name": "Conf Room Rainier",
"address": "Rainier#M365x330971.onmicrosoft.com"
},
{
"name": "Conf Room Stevens",
"address": "Stevens#M365x330971.onmicrosoft.com"
}
]
}

OAuth 2.0 And Google Cloud Print

I created a project called: "projectprint-123"
https://console.developers.google.com/apis/credentials/oauthclient?project=projectprint-123
Credentials
Web application
Name : projectprint-123
What to ask can the
1. Authorized JavaScript origins
2. Authorized redirect URIs
Put EMPTY? Because I testing localhost.
OK. I proceed to empty.
What is Oauth consent screen?
I only fill in Email address at this part.
OK. I proceed next.
Then I try
https://www.google.com/cloudprint/getauthcode?
printerid=5e0db751-9498-677d-9cf3-3a7284978279&oauth_client_id=254414591833-7lg4a5nnnh009g9ccf613notg8vceunp.apps.googleusercontent.com
Fail:
{ "success": false, "message": "Unknown, used or expired token.",
"request": {
"time": "0",
"params": {
"oauth_client_id": [
"254414591833-7lg4a5nnnh009g9ccf613notg8vceunp.apps.googleusercontent.com"
],
"printerid": [
"5e0db751-9498-677d-9cf3-3a7284978279"
]
} }, "errorCode": 506 }
I using this APIGEE application to send
https://apigee.com/console/others?req={%22resource%22%3A%22https%3A%2F%2Fwww.google.com%2Fcloudprint%2Fgetauthcode%22%2C%22params%22%3A{%22query%22%3A{}%2C%22template%22%3A{}%2C%22headers%22%3A{%22headers_name_0%22%3A%22Content-Type%22%2C%22headers_value_0%22%3A%22application%2Fx-www-form-urlencoded%22}%2C%22body%22%3A{%22attachmentFormat%22%3A%22mime%22%2C%22attachmentContentDisposition%22%3A%22form-data%22}}%2C%22verb%22%3A%22post%22}
I appreciate if you can help.
Thank you.

Resources