What ID should I use on the business discovery API? - instagram-graph-api

I'm trying to retrieve public stats from Instagram accounts using the business discovery API (https://developers.facebook.com/docs/instagram-api/business-discovery) but I'm not sure which node to use to retrieve this data. (I'm new on this API)
I have tried running the example on the site (
?fields=business_discovery.username(bluebottle){followers_count,media_count}) on graph explorer using:
/me
{
"error": {
"message": "(#100) Tried accessing nonexisting field (business_discovery) on node type (Page)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "D0siT4a4GR0"
}
}
my business account id (me?fields=instagram_business_account)
{
"error": {
"message": "(#100) Tried accessing nonexisting field (business_discovery) on node type (Page)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Hq0erqHbbxP"
}
}
my business account's Instagram user id (?fields=instagram_accounts)
{
"error": {
"message": "(#100) Tried accessing nonexisting field (business_discovery) on node type (InstagramUser)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "BCAkvwtsZXV"
}
}
Any guidance would be appreciated

In Graph API Explorer: first call /me/accounts. The API should return a list of Pages that you have a Role on, and their IDs:
Locate the Page that you connected to the Instagram Business Account and click its ID. This will populate the ID in the path field, automatically perform a GET request, and return the Page's name and ID fields.
Next, click in Search for a field and type instagram_business_account until it appears in the typeahead dropdown menu. When you see instagram_business_account, click it. This will append the field in the path using the fields parameter. Submit this new request, and you should get back the Instagram Business Account connected to this page.
Now that you have the Business Account ID, see this: https://developers.facebook.com/docs/instagram-api/getting-started

Related

Teams Export API not allowing me to filter by channel

I'm trying to use the Teams Export API to export a single Teams channel. I have my permissions set up properly; if I make a request to
https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages (without specifying a filter), I get the paginated results of all of the channel messages on my team. If I copy the sample datetime filters in that documentation, I also get a successful response with the appropriate results.
A successful response gives me a list of messages. Each one shows a channelIdentity field, which contains a channelId (fields removed for readability):
{
"value": [
{
"channelIdentity": {
"teamId": "{TEAM ID}",
"channelId": "{CHANNEL ID}"
},
},
]
}
What I want is to use this channelIdentity/channelId field as a filter on the results, so that I can export just the messages from a single channel.
If I run GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=channelIdentity/channelId eq '{CHANNEL ID}', I get an error:
{
"error": {
"code": "BadRequest",
"message": "The entity property 'channelIdentity/channelId' and operationKind 'Equal' is not allowed in $filter query.",
"innerError": {
"date": "2022-11-16T23:47:06",
"request-id": "...",
"client-request-id": "..."
}
}
}
This reads to me like I'm not allowed to use eq with this ID. If I try a 'starts with', I get a different error:
GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=startswith(channelIdentity/teamId, '{CHANNEL ID}')
{
"error": {
"code": "BadRequest",
"message": "Only binary operation expressions are allowed.",
"innerError": {
"date": "2022-11-17T00:11:26",
"request-id": "...",
"client-request-id": "..."
}
}
}
I'm unclear on what this is trying to say - either the ID starts with that phrase or it doesn't; it seems like a binary expression to me.
Is there some other approach I should use to get these results filtered by channel ID?
This API is designed to export everything from a team for backup/archival scenario. So, filtering by a specific channel is not supported now.
If you wish you may suggest this feature on Microsoft Feedback portal.
Any reason why you don't use List Channel Messages?
You can then make a GET call against this URL:
"https://graph.microsoft.com/v1.0/teams/{teamid}/channels/{channel id}/messages"
Note - as per that link you will need to Request access:
https://learn.microsoft.com/en-us/graph/teams-protected-apis
One other method, if you are using Graph Explorer, is add the signed-in user to the team as an owner, and it will let you test this method, you just won't be able to call via an App Registration until you do fill out that form.

createdBy and lastModifiedBy fields missing in drive search results in Microsoft Graph API

I'm sending a search request to the /me/drive/root/search endpoint. I'm specifying which fields to return using the $select query parameter as follows:
https://graph.microsoft.com/v1.0/me/drive/root/search(q='sdflkdshflkjhsdf')?$select=webUrl,name,lastModifiedDateTime,createdBy,lastModifiedBy,createdDateTime,folder,image,id
However the drive item objects returned are missing some of the fields I requested. For example here is the response to the above query:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
"#odata.nextLink": "https://graph.microsoft.com/v1.0/me/drive/root/search(q='sdflkdshflkjhsdf')?$select=webUrl%2cname%2clastModifiedDateTime%2ccreatedBy%2clastModifiedBy%2ccreatedDateTime%2cfolder%2cimage%2cid&$skiptoken=s!MTtlMDIzYmJlYi03NmUwLTRmMGUtYTljMy02MmE0MTNiM2RlZDE",
"value": [
{
"#odata.type": "#microsoft.graph.driveItem",
"createdDateTime": "2017-08-03T12:59:28Z",
"id": "01ZGVHW2FL7NNJJOD5AVGIMHTNV2BTATLB",
"lastModifiedDateTime": "2017-08-03T12:59:28Z",
"name": "sdflkdshflkjhsdf.pdf",
"webUrl": "https://[REDACTED].sharepoint.com/personal/oscar_[REDACTED]/Documents/sdflkdshflkjhsdf.pdf"
}
]
}
As you can see the createdBy and lastModifiedBy fields have not been returned. Are these fields not supported on this endpoint? The documentation says the endpoint returns full DriveItem objects which should include these fields.
I had same issue. In documentation is said, that
Drive Recent
Drive Item search that both should return the same object DriveItem.
When I tried to search
https://graph.microsoft.com/v1.0/me/drive/root/search(q='MY_RECENT_DOC.docx')?$top=1
gave me response without createdBy or lastModifiedBy.
But when i used 'recent API', the same object with the all information was presented.
https://graph.microsoft.com/v1.0/me/drive/recent?$top=1
Like #oscar-robinson said you can use id (what is always visible) and this id you can use to another search where all information will be presented.
https://graph.microsoft.com/v1.0/me/drive/items/{id}

Microsoft Graph SharePoint access items (read/write)

I am attempting to create a new list item in SharePoint Online using the [beta] Microsoft Graph endpoint. The goal is to call Microsoft Graph from an Outlook Add-in but the problem persists on Postman.
When I call the endpoint as per the documentation I get the following error message:
{
"error": {
"code": "unauthenticated",
"message": "The caller is not authenticated.",
"innerError": {
"request-id": "bb094f39-71c9-4c7d-9d9b-913cc9622baf",
"date": "2017-08-08T11:32:02"
}
}
}
I'm using ADAL JS to fetch the authentication token and I initialized my AuthenticationContext with my tenantID. My app has the following permissions: offline_access, Sites.Read.All, Sites.ReadWrite.All, User.Read
2nd Edit - more details on readItem
I use the https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items endpoint with the {site-id} of my desired site from /sites and the {list-id} of the list from /sites/{site-id}/lists but this is the empty response I get:
{
"#odata.context": "https://graph.microsoft.com/...",
"value": []
}
If I try to to add /{item-id} to my original call to access specific item I receive this response:
{
"error": {
"code": "itemNotFound",
"message": "The specified list was not found",
"innerError": {
"request-id": "6e7ccae3-3aee-4dbb-ae3e-de61250478e0",
"date": "2017-08-09T13:13:33"
}
}
}
Which doesn't make sense because I can retrieve valid information about the list if i make the call without /items/..
Any and all input appreciated :) I'll gladly provide more code, this is all I deemed relevant and didn't want to overcrowd the post.
might be that you actually don't have an item with that id, since https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items/1 works for me.
test the id's you really have by just https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items and each item returns it's id.

Unable to access the Sharepoint List using Microsoft Graph API--

Working with the Microsoft graph api and especially the sharepoint beta api and i am constantly running into issues. I know its beta, but still;)
SO the issue is When i tried to access the sharepoint list using Graph API in graph explorer
URL is: GET https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}
So SiteID i am passing my site tenant GUID and List ID as Sharepoint List GUID
and i am facing the error continously in Response
{
"error": {
"code": "invalidRequest",
"message": "Provided id is not suitable for the current host",
"innerError": {
"request-id": "61efc5b1-88f8-442c-a41d-7213b587318e",
"date": "2017-05-10T07:38:04"
}
}
}
IF any one also has faced this issue please let me know the solution you have resolved
The format of the ID's for sites have changed as part of a set of updates to the API this week. The new format is documented here, but it includes the SharePoint hostname, SPSite.ID, and SPWeb.ID as a triplet:
https://graph.microsoft.com/beta/sites/contoso.sharepoint.com,fc016e3c-d8ae-4ee0-a10c-de6d26788b6a,9a4ea7a5-c3c4-44ae-9f80-273bd67431b8
If you add the hostname into your IDs, your calls should start working again. You can discover the hostname by making a request to:
https://graph.microsoft.com/beta/sites/root/siteCollection/hostname
You can also search for sites now using the following search syntax:
https://graph.microsoft.com/beta/sites?search={keyword}
#Ryan Gregg has the correct answer
The SiteId is not just one GUID but a combination of <HostName,SPSite.ID,SPWeb.ID>.
Example: <contoso.sharepoint.com,fc016e3c-d8ae-4ee0-a10c-de6d26788b6a,9a4ea7a5-c3c4-44ae-9f80-273bd67431b8>
The whole string in the above example is what you should pass for {SiteId} in your request
If you dont have the SPSite.ID but have the URL for the site, you can make a GRAPH API call with relative path to the site
https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/Documetation
This call will return all the properties for the site and you can grab the full SiteId from here:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
"createdDateTime": "2020-04-23T12:18:48.653Z",
"description": "Documentation",
"id": "contoso.sharepoint.com,fc016e3c-d8ae-4ee0-a10c-de6d26788b6a,9a4ea7a5-c3c4-44ae-9f80-273bd67431b8",
"lastModifiedDateTime": "2020-12-09T19:17:21Z",
"name": "Documentation",
"webUrl": "https://contoso.sharepoint.com/sites/Documentation",
"displayName": "Documentation",
"root": {},
"siteCollection": {
"hostname": "contoso.sharepoint.com"
}
}
Try https://graph.microsoft.com/beta/sites/{siteCollectionId},{siteId}/lists
You can find these ids from https://graph.microsoft.com/beta/site/sites

Facebook API post not available

With certain facebook posts, that are seemingly completely public (for example) I am unable to pull their information from the graph API no matter what combination of permissions / application / access_token I give it.
Even worse, I just get a generic error:
https://developers.facebook.com/tools/explorer?method=GET&path=10153801897821136&version=v2.5
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "GU3r05xB4VK"
}
}
It seems that for whatever reason facebook has decided that I shouldn't be able to view this post (likely because of privacy settings) but I can very obviously view the actual post on facebook, even as a logged out user.
Any thoughts as to how to get this to work via the API?
Within Facebook API, a public post that can be retrieved, refers to a post published by a Facebook page not a Facebook user profile.
In order to view this post, you will need user_posts and user_friends for the owner of that video and the querying user.
So for querying userA to get a public video from userB (who is a friend of userA), the permissions for both are
{
"data": [
{
"permission": "user_friends",
"status": "granted"
},
{
"permission": "user_posts",
"status": "granted"
},
{
"permission": "public_profile",
"status": "granted"
}
]
}

Resources