Access token Facebook graph api? - facebook

After created an app on FB, I get an access token XXX
when I open https://graph.facebook.com/me/likes?access_token=XXX it does show all information that I likes fine.
but when I open to see from another user (who set those info public,such as https://graph.facebook.com/4/likes?access_token=XXX ) I got nothing but
{
"data": [
]
}
Can somebody expand to me why and any idea solve?

You can not view the likes of a public profile, you have to ask for permission(user_likes) from the app to see this info.
Info on the user_likes permissions
user_likes: Provides access to the list of all of the pages the user has liked as the likes connection
Example of Public profile(sorry btaylor, but your name is on the docs )
https://graph.facebook.com/btaylor/likes?access_token=xxx
You will see an empty data set.
From the user docs, talking about the likes connection:
Read
You can read the pages that a User has liked by issuing an HTTP GET to /PROFILE_ID/likes with the user_likes or friends_likes permissions. For example:
https://graph.facebook.com/me/likes

Related

Post to Instagram via Facebook Graph API - unable to get the correct ig-user-id permission

I need to create a Meta application that posts scheduled content on the Instagram page of the company. The app is now in dev mode, and used through the Graph API and cURL.
After getting an Instagram user token on the Graph Explorer with all the required permissions (email, pages_show_list, ads_management, business_management, instagram_basic, instagram_content_publish, publish_to_groups, pages_read_engagement, pages_manage_posts, public_profile) and getting the ig-user-id through the GET /v13.0/me?fields=id,name API call, i make the container generation call, as described in the docs:
curl -i -X POST https://graph.facebook.com/{{ig-user-id}}/media?
image_url=https://{{image-url}}&caption={{text}}&access_token={{token}}
To which I get as a response:
Unsupported post request. Object with ID '{{ig-user-id}}' does not exist, cannot be
loaded due to missing permissions, or does not support this operation.
I tried to generate a Page token in spite of an User token, to use the Page ID in spite of the Used scoped app ID provided by the Graph API but the result has always been the same. One thing I noticed is, trying to get the IG user ID as described on the getting started page, point 5, to my request:
curl -i -X GET "https://graph.facebook.com/v13.0/{{page-id}}?
fields=instagram_business_account&access_token={{token}}"
The response is just {"id":"{{page-id}}"} in spite of the expected
{
"instagram_business_account": {
"id": "17841405822304914" // Connected IG User ID
},
"id": "134895793791914" // Facebook Page ID
}
So it appears it might be a permissions issue. Now, on the Business Settings for the business the app is related:
I'm listed under Users -> People as Administrator and Developer
I'm listed under Account -> Instagram Account -> People with all the permissions (Content, Community Activity, etc.) granted but messages (Impossible to assign - Available only on Instagram)
I'm listed onder Account -> Apps -> {{App Name}} -> People twice with all permissions granted.
Could anyone help me solve the issue? Thanks in advance.

How to generate a URL for chatting with a user in a Facebook page using the page scoped id PSID

We have a chatbot on Facebook Messenger Platform, we want to provide the admins an URL to chat with a specific user, for example: https://facebook.com/<page-id>/u/<user-psid>
Currently when opening a chatting thread in a Facebook page URL is https://www.facebook.com/<page-id>/inbox/?mailbox_id=<page-id>&selected_item_id=<user-id>
when we tried replacing the user-id with the PSID it didn't work.
Is there a way to achieve this? we just want a URL to redirect to Facebook page chatting with a user who already talked to the bot and we have his/her PSID.
You can not go to inbox using PSID. You would need ASID. You can get ASID from PSID by following this process: https://developers.facebook.com/docs/messenger-platform/identity/id-matching/ . After that, you would need read_page_mailboxes permission. It is going to deprecate from December, 2019. Read about it here: https://developers.facebook.com/docs/facebook-login/permissions/
Given the PSID, you can use Page conversation API to query the conversations of Page.
GET /v7.0/{page-id}/conversations?user_id={PSID}
Host: graph.facebook.com
This API returns Page conversations and links that you can use to open in your browser:
{
"data": [
{
"id": "t_10523963545045c18",
"link": "/My-PAGEXXX/inbox/119226229829XXXX/",
"updated_time": "2020-06-21T23:XX:XX+0000"
}
]
}
Ref: https://developers.facebook.com/docs/graph-api/reference/page/conversations/

Facebook graph api empty data when getting user likes

I'm using a Facebook application that get all user likes in order to check if a given page is liked using
https://graph.facebook.com/{USER_ID}/likes?access_token={MY_ACCESS_TOKEN}
Everything works fine for me and for the most part of the users, except for some users, that return this:
{
"data": [
]
}
Why does it return an empty data? I already requested the authorization for user_likes in the application
Apps only have access to a user's public information. Even with user_likes permission you will get no Likes data from a user that has set their Likes to private.

Why Graph API Explorer doesn't return the wall 'feed' based on a group's id

When I test the Graph API Explorer from facebook site and write the following parameters:
https://graph.facebook.com/'groupid'/feed?access_token='my access token'
it returns
{
"data":
[
]
}
I tried it with several group ids and all return the same result, while if I try members instead of feed it returns the list of members.
Is there a bug in the feed of a group?
Here is how you can generate the issue:
Get an access token: xxxxx
Get any Group ID: 123456
Make the graph api explorer call to retrieve the group's wall based on the group id
https://graph.facebook.com/123456/feed?access_token=xxxxxxx
The thing is I first thought the problem was from my code, but when I tried it from facebook graph api explorer I found out that its not returning any results.
Please I would really appreciate the help as this is part of my master's project and the due is within two weeks!!
Assume group id is 481298561918120, please visit https://developers.facebook.com/tools/explorer/?method=GET&path=481298561918120%2Ffeed
If you see
{ "data": [ ] }
, you should click the "Get access token" button on your right-hand, then click/check "user_groups". Finally, click "Get Access Token" and process the dialog to grant permission
After you granted the permission, try to click "Submit" button. Now you should able to see the feed.
Conclusion: make sure you have granted user_groups permission. You can check the permission on "Scope" field at https://developers.facebook.com/tools/debug
As of api version 2.8 the following requirements should be met.
Any valid access token if the group is public (i.e. the group's privacy setting is OPEN)
If the group is not public:
The user_managed_groups permission should be acquired
And user should be an admin of the group you are about read.
Here is the catch
To use the user_managed_groups permission you need to submit your app for review.
Login Review: https://developers.facebook.com/docs/facebook-login/review/what-is-login-review
Otherwise you are left with the response:
{
"data": [
]
}
Group Feed API Source: https://developers.facebook.com/docs/graph-api/reference/v2.8/group

Retrieving facebook user wall posts through graph API

I'm currently working on a facebook app which captures wall posts for a specified user, page or group, after a user has authorized the app I quote the access_token that is returned to call the method
https://graph.facebook.com//feed?access_token=
this works fine for pages and groups as we only need a valid token, however for users the results are different depending on the relationship between the user who authorized the app the user whose posts are being captured.
For example if there is no relationship between the two users some posts are not returned even though they are public and displayed when you view the profile of the user, however if they are friends more posts are returned.
Can someone please explain this behaviour? And is it possible to obtain all posts using this method?
Yes, per the permissions listed at https://developers.facebook.com/docs/reference/api/permissions the results of the call are different depending upon the relationship.
However when things are public and you use an access token that doesn't belong to the user, then no results are returned. I cannot remember a time when this wasn't this way. For some odd reason (by design or omission on Facebook's part) using the graph API to get at public posts using a user access token just doesn't want to work.
For example, You can see some public items here
http://www.facebook.com/zuck
http://graph.facebook.com/zuck
However, you cannot seem to get any feed from here without an access token
https://graph.facebook.com/zuck/feed
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException"
}
}
Let's try adding an user access token that does not belong to zuck or a friend of zuck. https://graph.facebook.com/zuck/feed?access_token={UserAccessToken}
And here's what we get:
{
"data": [
]
}
What about an app access token? Let's try
https://graph.facebook.com/zuck/feed?access_token={AppAccessToken}
{
"error": {
"message": "Invalid OAuth access token signature.",
"type": "OAuthException"
}
}
So as you can see, it's difficult to get things via the graph that are not in alignment with your access token.
I manage to get most of the feeds from user's wall post. Although this is a old post, I hope someone can manage to get what they want from my answer.
Before getting the access token(to get the feeds), you need to add multiple correct Read Permissions "keys".
For example, you will have to add "read_stream", and "user_status" (which I found that these are the most important permission "key" to generate the correct access token, to retrieve one's so-called "public" feeds).
You can add more into generating the access token, in either you want the permission to GET, or POST, or BOTH.
Source is here: https://developers.facebook.com/docs/howtos/ios-6/#nativeauthdialog
One thing that I found is, the way to get the feeds result from user's "Home/About" page and Facebook Page (which is created for people to like (not add friends)) are different. The key is mentioned above, "read_stream", and "user_status". So it's better that you add both of the permissions in order to generate the access token to get everything in feeds.
Graph API doesn't return posts to the App if is not authorized to read user feed, even if posts are public.
Source: https://developers.facebook.com/bugs/290004301178437/
According to the latest api ,
FB.api("/me/feed","get",function(response) {//callback})
should do and also work well .
It is working now but facebook may change it in future.