Youtube.analytics.query api giving forbidden error - node.js

I want to fetch the analytics of any channel of youtube that basically are not owned by me. I am using this API.
If this is not the right API please suggest me how to achieve this.
Also, I am using node.
https://youtubeanalytics.googleapis.com/v2/reports?dimensions=day&endDate=2019-01-01&ids=channel%3D%3DUCZSNzBgFub_WWil6TOTYwAg&metrics=likes&startDate=2018-01-01
Response:
{
"error": {
"code": 403,
"message": "Forbidden",
"errors": [
{
"message": "Forbidden",
"domain": "global",
"reason": "forbidden"
}
]
}
}

You need to understand the difference between private and public data. Public data is data that can be accessed by anyone. Public videos on YouTube for example
Private data is data that is owned by a user. A good example of that would be the analytics for a channel on Youtube. You cant access this kind of information without the permission of the user who owns it.
{
"error": {
"code": 403,
"message": "Forbidden",
"errors": [
{
"message": "Forbidden",
"domain": "global",
"reason": "forbidden"
}
]
}
}
Means that the currently authenticated user doesn't have permission to do what you are trying to do. You need to login with a user who has access to this data. I suggest you ask the owner of the channel to give you access.

Related

Graph REST API - Cannot access a DriveItem's ListItem

I'm using the rest api to access my drive's items.
I can access the items perfectly fine like this:
https://graph.microsoft.com/v1.0/drives/{{driveid}}/items/{{folderid}}/children
But this is where my problems lie:
This:
https://graph.microsoft.com/v1.0/drives/{{driveid}}/items/{{folderid}}/children?expand=fields
Gives this result:
{
"error": {
"code": "invalidRequest",
"message": "Could not find a property named 'fields' on type 'oneDrive.item'.",
"innerError": {
"date": "2021-09-02T10:50:12",
"request-id": "075bf9b7-c93a-43d2-a1ed-bd4563399f1a",
"client-request-id": "075bf9b7-c93a-43d2-a1ed-bd4563399f1a"
}
}
}
And this:
https://graph.microsoft.com/v1.0/drives/{{driveid}}/items/{{folderid}}/children?expand=listitem
Gives this result:
{
"error": {
"code": "invalidRequest",
"message": "Could not find a property named 'listitem' on type 'oneDrive.item'.",
"innerError": {
"date": "2021-09-02T10:50:30",
"request-id": "2db87d5f-fbe9-42ad-a61e-a377bafafcad",
"client-request-id": "2db87d5f-fbe9-42ad-a61e-a377bafafcad"
}
}
}
I've tried ?$expand=fields and that gives me this message:
"Parsing OData Select and Expand failed: Could not find a property named 'fields' on type 'microsoft.graph.driveItem'."
What am I doing wrong? Because I have another separate SharePoint site and the ?expand=listitem works perfectly.
I've managed to get a decent workaround by using the Graph SDK:
graphClient
.Sites[SiteID]
.Drives[DriveID]
.Items[FolderID]
.Children
.Request()
.Expand(item => item.ListItem)
.GetAsync();

I'm unable to Send chatMessage in a channel or a chat using Microsoft Graph API

I was just trying to access the Send chatMessage in a channel or a chat using the microsoft grah API. Also given the required permissions for the for my application both Delegant & Application level.
API Used : POST https://graph.microsoft.com/v1.0/teams/fbe2bf47-16c8-47cf-b4a5-4b9b187c508b/channels/19:4a95f7d8db4c4e7fae857bcebe0623e6#thread.tacv2/messages
Content-type: application/json
{
"body": { "content": "Hello World" }
}
Postman Response: 401
{
"error": {
"code": "Unauthorized",
"message": "Unauthorized",
"innerError": {
"date": "2021-07-16T16:34:49",
"request-id": "ddd9c7ad-f84b-423f-88fc-630330bad600",
"client-request-id": "ddd9c7ad-f84b-423f-88fc-630330bad600"
}
}
}
Graph API Explorer Response : 403
Documentation URL : https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http
Thanks in Advance.
I tried this using graph explorer and I was able to send the message.
Note : Please make sure you have the above required permissions to send the message to the channel.
Reference:
Send chatMessage in a channel or a chat - Microsoft Graph v1.0 | Microsoft Docs

How to create a user using azure graph api

I am trying to create a user using azure graph API. For this, I have got the token response as below:
Once I have the token, I have added this as bearer token in Authorization for the below url:
https://graph.microsoft.com/v1.0/users
and posting the below json data:
{
"accountEnabled": true,
"displayName": "Andrew",
"mailNickname": "SanAndrew",
"userPrincipalName": "andrew.san204#gmail.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password"
}
}
But getting below error:
{
" error": {
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.",
"innerError": {
"request-id": "c06079d2-ff6b-4e5b-b34d-704f16bc312f",
"date": "2019-06-03T11:20:20"
}
}
}
although I have all the permissions as shown below:
Can anyone please suggest what I am doing wrong here.
One possibility for the error is that you are trying to create a user with gmail.com domain. The domain needs to be one of the verified domains in your AAD tenant.
If you want to add a gmail.com user anyway, you need to send an invitation through the invitations endpoint: https://learn.microsoft.com/en-us/graph/api/invitation-post?view=graph-rest-1.0&tabs=cs

Is there an Instagram API/Graph API for finding the Instagram Profile Type (Business/Personal)?

I am using the Graph API to get details from business users. Since most of the Profile is Non-Business, would like to find-out, if there is an API to get the Profile Type?
During the trial, I keep getting the following message and also discovered sometime the API is misbehaving..
{
"error": {
"message": "Invalid user id",
"type": "OAuthException",
"code": 110,
"error_subcode": 2207013,
"is_transient": false,
"error_user_title": "Cannot find User",
"error_user_msg": "The user with username: rohit_xxx cannot be found.",
"fbtrace_id": "FkKgUvBdJWZ"
}
}
So, If I know the Profile Type in advance, We can handle the response in much better way..
Thanks in Advance..
The instagram Graph API is designed to work with creator/business accounts. This is specified in multiple places.
If a user doesn't have business/creator account, the instagram id would be empty in the response.
curl -i -X GET \
"https://graph.facebook.com/v3.2/{fb-page-id}?fields=instagram_business_account&access_token={access-token}"
Response:
{
"instagram_business_account": {
"id": "" // Connected IG User ID
},
"id": "134895793791914" // Facebook Page ID
}

Adding User to Group using Graph API B2C

I am using Azure AD B2C to create users.
After a user is created I would like to add them to a Group
Using Postman I have made the following request (with access token in the header). Note: I have managed to successfully create a group using the Api.
POST
https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members/$ref?api-version=1.6
With Body:
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}
Which is what the documentation specifies. No matter the body that is sent I get the following error
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "The request URI is not valid. Since the segment 'members' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource."
},
"requestId": "48cf65f3-20ba-411e-8121-f7ea54252f3a",
"date": "2019-05-27T06:09:25"
}
}
I tried removing the /$ref
POST
https://graph.windows.net/{azure-tenant}/groups/{group-objectId/members?api-version=1.6
Body:
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/directoryObjects/{user-objectId}"
}
as well as
{
"#odata.id": "https://graph.windows.net/{azure-tenant}/users/{user-objectId}"
}
Now the error that gets returned now is:
{
"odata.error": {
"code": "Request_BadRequest",
"message": {
"lang": "en",
"value": "Unsupported resource type 'DirectoryObject' for operation 'Create'."
},
"requestId": "2c36cc6d-383c-44f8-8609-2ac3e3efc862",
"date": "2019-05-27T06:15:26"
}
}
The documentation that I have been using https://learn.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=javascript
You are using graph.windows.net endpoint, so you should refer to azure ad graph api.
POST https://graph.windows.net/myorganization/groups/b4bda672-1fba-4711-8fb1-5383c40b2c14/$links/members?api-version=1.6
{
"url": "https://graph.windows.net/myorganization/directoryObjects/3eb6055a-baeb-44d4-a1ea-2fee86d8891b"
}
The document you referred to is microsoft graph api. The endpoint should be https://graph.microsoft.com.
You can use Microsoft Graph explorer to call these apis.

Resources