Graph API Score with GET method can't return score field - facebook-graph-api

I use Facebook SDK 4.2.0 Android to create the leader scoreboard for my game.
I post successfully my score with POST method at /me/scores graphPath:
{Response: responseCode: 200, graphObject: {"success":true}, error: null}
However, when I try to GET the score at /me/scores as well as /793295994100883/scores (793295994100883 is my APP ID), I didn't see my score in JSON result string.
{Response: responseCode: 200, graphObject: {"data":[{"user":{"id":"Facebook USER-ID","name":"Facebook USER-NAME"}}]}, error: null}
In https://developers.facebook.com/tools/explorer, It return my expected string when I get at /793295994100883?field=scores{score}
"scores": {
"data": [
{
"score": 1234,
"user": {
"name": "Facebook USER-NAME",
"id": "Facebook USER-ID"
}
}
]
},
"id": "793295994100883"
Please help with this issue. How can I get score with Facebook SDK?
Thanks!

Which version of the Graph API is your app using? If it's v2.4, you have to specify each field you want to retrieve.
Have a look at my answer here:
Facebook only returning name and id of user

Related

Instagram: Graph API does not return id of user who commented

I am using Facebook Graph v7.0 to access Instagram data.
I can get comments made on instagram media using the following query:
Request:
https://graph.facebook.com/v7.0/18132613492054980?fields=id,ig_id,caption,timestamp,owner,username,media_type,permalink,children,comments.limit(100){hidden,id,like_count,media,text,timestamp,user,username},comments_count&access_token
Response:
{
"id": "18132613492054980",
"ig_id": "2263043983231761272",
"caption": "Sprite",
"timestamp": "2020-03-12T06:51:27+0000",
"owner": {
"id": "17841430463493290"
},
"username": "jobyjohn123456",
"media_type": "IMAGE",
"permalink": "https://www.instagram.com/p/B9n8oM7nTt4/",
"comments": {
"data": [
{
"hidden": false,
"id": "18132938077057326",
"like_count": 0,
"media": {
"id": "18132613492054980"
},
"text": "Nice sprite \u0040yziaf__07",
"timestamp": "2020-03-12T06:52:27+0000",
"username": "zimba_birbal"
}
]
},
"comments_count": 2
}
In the response, I do not get the User Id of user who commented. It just includes the username of the commenter.
Though, I pass user in the query, the result does not include it.
Do I need any special permission to get user id of the user who commented in the comment response?
There is Facebook API "business discovery" to get the user details of other Instagram User.
API request:
https://graph.facebook.com/178430463490?fields=business_discovery.username(user_name_you_wantto_get_its_IgUserId){followers_count,media_count,username,ig_id}
Response:
We can pass the user name in that API request, then we will get the Instagram User Id.
The documentation says it has one limitation, this will not work for "age-gated Instagram Business IG Users" but I do not exactly know what it means. When I tested for both older Instagram account and new Instagram account (just recently created account) and this API is returning data for both.
When I tested for private Instagram account, it did not work so it seems this api works only for business account.
If that api does not work, there is one workaround. The following request help to get User Id using its username but I have not found any API documentation regarding this API. It looks like this is not a standard API and moreover it does not need any token.
https://www.instagram.com/user_name_you_wantto_get_its_IgUserId/?__a=1

Question about Karate test case for POST method

I have an endpoint URL, within Swagger I must pass certain fields to test the POST method. I was wondering if anyone had an example of how to set up a Karate test for a POST method?
Yes, there are plenty in the documentation: https://github.com/intuit/karate
If you follow the quickstart, you will get a sample project with a working POST: https://github.com/intuit/karate#quickstart
Scenario: create a user and then get it by id
* def user =
"""
{
"name": "Test User",
"username": "testuser",
"email": "test#user.com",
"address": {
"street": "Has No Name",
"suite": "Apt. 123",
"city": "Electri",
"zipcode": "54321-6789"
}
}
"""
Given url 'https://jsonplaceholder.typicode.com/users'
And request user
When method post
Then status 201

Facebook Graph Api publishing to feed returns: "(#100) Param place must be a valid place tag ID"

I am searching at Facebook Graph Api, using graph api explorer, for some place using the following endpoint:
/search?type=place&q=centauro&fields=id,name,link
I am getting this as response:
"data": [
{
"id": "492103517849553",
"name": "Centauro",
"link": "https://www.facebook.com/Centauro-492103484516223/"
},
{
"id": "313439499156253",
"name": "Centauro",
"link": "https://www.facebook.com/Centauro-313439462489590/"
},
{
"id": "175812113006221",
"name": "Centauro",
"link": "https://www.facebook.com/Centauro-175812079672891/"
},
{
"id": "1423220914594882",
"name": "Centauro",
"link": "https://www.facebook.com/pages/Centauro/1423220891261551"
},...
When I try to publish using the field "id" returned:
/me/feed
with fields:
message: Testing
place: 492103517849553
I get the following reponse:
{
"error": {
"message": "(#100) Param place must be a valid place tag ID",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "DfEKOjZX8g+"
}
}
But if I use de final number of the link:
"link": "https://www.facebook.com/Centauro-492103484516223/"
492103484516223
And try again:
/me/feed
with fields:
message: Testing
place: 492103484516223
It works perfectly.
So, is there a way to get te correct place id for publishing? Or is it a bug?
I was also getting the “(#100) Param place must be a valid place tag ID” error, but got it to go away by providing a JSON string within the 'place' element.
So where the content of your request was this:
place: 492103484516223
Format the place information like this instead:
place: {"id": "492103484516223"}
Currently, this is how you can solve it.
import requests
IG_USER_ID = <YOUR INSTAGRAM USER ID>
USER_ACCESS = <YOUR USER ACCESS TOKEN WITH VALID PERMISSIONS>
CONTAINER1_ID = <ID OF FIRST CONTAINER>
CONTAINER2_ID = <ID OF SECOND CONTAINER>
URL = f"https://graph.facebook.com/v13.0/{IG_USER_ID}/media?caption=Fruit%20candies&media_type=CAROUSEL&children={CONTAINER1_ID}%2C{CONTAINER2_ID}&access_token={USER_ACCESS}"
r = requests.post(URL)

Facebook API process shared object [duplicate]

I just tried through the Graph API Explorer with this path /v2.4/10153513872748291 and I've got this result:
{
"error": {
"message": "(#12) singular links API is deprecated for versions v2.4 and higher",
"type": "OAuthException",
"code": 12
}
}
But https://developers.facebook.com/docs/reference/api/post/ doesn't say anything about deprecation.
I'm not sure if I miss something, or there's another way to get info about an individual post.
Edit: v2.3 works, but v2.4 is the latest one.
Looks like you now need to the combination of the id of the user or page that made the post (or whose wall it is on), an underscore, and then the post id.
For your example post, 10153513872748291, that is made by a page Drama-addict, that has the id 141108613290 – so 141108613290_10153513872748291 will work.
And so does 788239567865981_10153513872748291, because 788239567865981 is the id of the user making the post.
Firstput userId underscore add postId /Likes to check Like status in facebook
userId_post_Id/Likes to fetch Likes Records
userId_post_Id/Comments to fetch Comments Records
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=303261006522998_751199848395776%2FLikes&version=v2.9
**In this link Right side Get Token indide GetAccessToken to select Permission**
303261006522998_751199848395776/Likes
303261006522998_751199848395776/Comments
{
"data": [
{
"id": "124778301449917",
"name": "Manisha Gera"
},
{
"id": "1680577265523548",
"name": "Rubi Sharma"
}
],
"paging": {
"cursors": {
"before": "MTI0Nzc4MzAxNDQ5OTE3",
"after": "MTY4MDU3NzI2NTUyMzU0OAZDZD"
}
}
}

Facebook Graph API V 2.6 User Type

Is there a way to know if the user info being returned by the graph api explorer is a user's profile or a business page?
The query I am using is:
me?fields=feed{from,comments{from}}
which gives me back all the users who have left a comment or a post on my page.
Here is an example of what I would get back for that query:
{
"feed": {
"data": [
{
"from": {
"name": "John's Tires",
"id": "114615108955555"
},
{
"from": {
"name": "John Smith",
"id": "123615108951010"
},
Is there something I can add to the query to make it return a user type? For example- type:user or type:page?
I've searched facebook graph api documentation and found nothing. Thanks in advance for your help.
With metadata=1 you get a type in the response for a single top level item, but I don't know how to do it for a list.
$ fbapi /me?metadata=1 | jq .metadata.type
"user"
$ fbapi /BBCQuestionTime?metadata=1 | jq .metadata.type
"page"