Getting wrong mutual friends count from facebook - php

I am trying to get mutual friends from facebook but it is giving me wrong result. The total number of mutual friends count which I am getting is right but when the data is users is not coming
Request
https://graph.facebook.com/v2.8/1744744292507346?fields=context.fields(mutual_friends{name,picture.type(large)})&access_token=access_token
Response
{
"context": {
"mutual_friends": {
"data": [
{
"name": "Gaurav Varshney",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15541198_1872071033026134_3669335060573505093_n.jpg?oh=d4a95ee6cdb8d401be06e8f10fbf6d50&oe=59B0C911"
}
},
"id": "1919297771636793"
}
],
"paging": {
"cursors": {
"before": "MTkxOTI5Nzc3MTYzNjc5MwZDZD",
"after": "MTkxOTI5Nzc3MTYzNjc5MwZDZD"
}
},
"summary": {
"total_count": 2
}
},
"id": "dXNlcl9jb250ZAXh0OgGQHYKW1ALzRNZBAkUhMk2uDFtLZBBkzlasCZAq98zEqnPZBjqy7beHZBJZCVZB7STTw6yMnKC0w4qDA05ZBOGQ3RdRoPjfi1cbAmnChBQ1xLYpJuuKrIEZD"
},
"id": "1744744292507346"
}
I am only getting 1 friend since total_count is showing 2 .Can anyone tell me where I am doing wrong?And how can I use paging ??
When try to hit all_mutual_friends
https://graph.facebook.com/v2.8/1744744292507346?fields=context.fields(all_mutual_friends{name,picture.type(large)})&access_token=access_token
{
"error": {
"message": "(#10) To use all_mutual_friends on behalf of people who are not admins, developers and testers of your app, your use of this endpoint must be reviewed and approved by Facebook. To submit this feature for review please read our documentation on reviewable features: https://developers.facebook.com/docs/apps/review",
"type": "OAuthException",
"code": 10,
"fbtrace_id": "HF3ZO8U3eLW"
}
}

There is a lack of documentation about this feature and I had to dig about it. Mainly regarding on how to request that with Graph API.
That's how I'm doing and it is working, with some flaws that I will explain later:
Let's say we have here UserA and UserB. You need to collect the context-id of each of the user and save it on the server side because it must be used later on.
So, UserA connects and want to request mutual friends with UserB which is already connected. What you will need to do is:
UserA FB Graph request using this:
/'{{UserB context-id}}/all_mutual_friends?limit=5000', 'get'
also sending UserA fbaccesstoken
I use the limit 5000 to avoid pagination on the data results.
Now, the flaws:
The all_mutual_friends is giving me some headaches. I may be completely wrong, of course, but I debugged it for days and it seems there are some issues with Facebook when the feature is still in development mode and not public/authorized by FB. Don't know, I need to ask for permission to see that in production.
On my application I realised there are sometimes some mutual_friends are not actually listed and it is not a fault of the script, but probably some users configuration that avoid using this or some facebook problem. IDN.
Anyways, that's the way you should request mutual friends.
Hope it helps.

Related

Watson Assistant CURL API: How to send follow up message?

I'm trying out IBM Watson Assistant. Ultimate goal is to integrate it with my custom PHP backend, via it's Watson Assistant's cURL API Endpoints (because there's no complete PHP SDK yet).
Let me tell what I did so far:
Imported a sample Workspace from a Training Data Set.
Then I tried this, and it works fine.
Then I tried that exact same thing via cURL API, I got a response like this: (The json output format beautified)
.
{
"intents": [
{
"intent": "locate_amenity",
"confidence": 0.999901008605957
}
],
"entities": [
{
"entity": "amenity",
"location": [
7,
10
],
"value": "gas",
"confidence": 1
}
],
"input": {
"text": "i need some gas"
},
"output": {
"text": [
"Hi. It looks like a nice drive today. What would you like me to do? "
],
"nodes_visited": [
"Start And Initialize Context"
],
"log_messages": []
},
"context": {
"conversation_id": "153c18ee-1015-4b6a-ae04-789e29bf4a05",
"system": {
"dialog_stack": [
{
"dialog_node": "root"
}
],
"dialog_turn_counter": 1,
"dialog_request_counter": 1,
"_node_output_map": {
"Start And Initialize Context": [
0,
0
]
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"AConoff": "off",
"lightonoff": "off",
"musiconoff": "off",
"appl_action": "",
"heateronoff": "off",
"volumeonoff": "off",
"wipersonoff": "off",
"default_counter": 0,
"previous_cuisine": "",
"previous_restaurant_date": "",
"previous_restaurant_time": ""
}
}
Now please let me understand 2 things here.
Question (1)
At this point, I was expecting the API to return with a message:
"There are gas stations nearby. Which one would you like to drive to?"
But why it doesn't. If then, how do I achieve it?
Question (2)
How do I properly reply back with "Go to number 5." so that the API understands I'm referring to the previous Call? (aka) How to I continue the dialog flow? (Note: I tried sending back with the previous "contexts", "entities", "intents", but it is somehow still recognised as a new message.)
Please share me an example of cURL call to follow up the previous message.
Since there's no complete PHP SDK yet, it is very hard for me to understand just by the cURL API calls. API Documentation does not explain to that details too. Please help.
Thank you all.
The message API for Watson Assistant is stateless. Everything that is needed to process a request is submitted as parameters. This includes the message itself, but also the context. The context holds the state about where in the dialog tree the conversation is. It could also hold information that is transferred from WA to the app, e.g., to process a client-side action. Or from the app to WA, e.g., with a record from a database.
Coming to your request:
Your dialog probably sends out that reponse when a new conversation is started. I see it is the same as in the "Try it out".
You would need to send a "Hi" or empty message first, wait for the reponse from WA, then send your "I need gas" together with the context data you received from WA. WHen you look into the details, you see the dialog stack, turn counter and more. The conversation ID is the identifier for that current chat.
With the above, WA's next response should be exactly like in the "Try it out" because you went down in the dialog tree.

Riot API server callback

I am making website to organize tournaments in League of Legends game. I have problem with receiving data about completed games from automatic callback.
The steps which we take:
We register provider with tournament-v3:
http://example.pl/riotcallbackinfo
on server EUNE
and recive id=10xx
We register tournament, and create tournament code successfully.
tournamentId=256xxx
code: EUNE043bb-xxx4d390-xxxx-4f2c-xxxx-4dc266xxxxxx
3. We play game with generated tournament code and completed it successfully.
After the match we should receive some data to our url:
example.pl/riotcallbackinfo
but nothing is sending. We have log system to check every time someone call this url and there is no information about calling it by riot api.
We can get data about this completed game using match-api-v3 and it is looked, like game is finished successfully.
We tried to register also http://example.pl:80/riotcallbackinfo url, but with no success.
To backed we use Laravel PHP 5.4. The documentation says:
"The following ports are forwarded to your Homestead environment:
HTTP: 8000 → Forwards To 80"
Lobby events for this game are:
{
"eventList": [
{
"timestamp": "1498128797694",
"summonerId": "23509512",
"eventType": "PracticeGameCreatedEvent"
},
{
"timestamp": "1498128833935",
"eventType": "GameAllocationStartedEvent"
},
{
"timestamp": "1498128803131",
"eventType": "ChampSelectStartedEvent"
},
{
"timestamp": "1498128798414",
"summonerId": "34477543",
"eventType": "PlayerJoinedGameEvent"
},
{
"timestamp": "1498128834399",
"eventType": "GameAllocatedToLsmEvent"
}
]
}
We have tested our url method with Postman and sending your sample JSON response and everything worked fine. Even if our method is broke we should see something in log. Our log is set at the beginning of the method.
Could you suggest us, were could have problem? Why couldn’t we get data from automatic callback? There is problem with our URL or is something what we understand wrong?
Thank you in advance for your help

Google Datastore returning "503 Backend Error"

I'm sending the following request to the Google Datastore API, via the PHP client, and i'm getting a "503 Backend Error" without any other information. I tried the online client available here, but the error is the same. Maybe something is malformed on my request? The documentation wasn't very helpful:
{
"mode": "NON_TRANSACTIONAL",
"mutation": {
"upsert": [
{
"key": {
"path": [
{
"kind": "Log"
}
]
},
"properties": {
"event": {
"indexed": false,
"stringValue": "new_order"
},
"dataType": {
"indexed": false,
"stringValue": "test"
}
}
}
]
}
}
Any ideas of what might be causing this behavior? Or how to enable more detailed feedback from the API?
When you perform POST https://www.googleapis.com/datastore/<APIversion>/datasets/<datasetId>/commit, make sure that if you created your project using the old Admin Console that your datasetId in the URL is the App Engine application ID, and that if you created your project using the Developer Console, that your datasetId is the project ID you see in the Developer Console.
Also, if you created your project through the new Developer Console, try toggling the API on and off.
Finally, check that you are completing the OAuth flow properly, all your client ID info makes sense, and that you are setting up the right scopes, etc...

Inconsistency from Graph API

I'm currently writing a PHP application.
I noticed something strange when it wasn't returning the persons birthday.
To cut a long story short, when i manually query the graph api, it gives me the full result set (birthday, email etc. included). However, when I run it in my app, it comes back as if i've not sent the access token.
When I manually visit the address it produces:
{
"id": "507665705",
"name": "Ally Dewar",
"first_name": "Ally",
"last_name": "Dewar",
"link": "https://www.facebook.com/alastair.dewar",
"username": "alastair.dewar",
"birthday": "06/22/1990",
"location": {
"id": "113744028635772",
"name": "Greenock"
},
"gender": "male",
"email": "alastair\u0040alastairdewar.co.uk",
"timezone": 1,
"locale": "en_GB",
"verified": true,
"updated_time": "2012-03-11T15:56:19+0000"
}
However, when my application makes the same request (exact same URL), it comes back with
{"id":"507665705","name":"Ally Dewar","first_name":"Ally","last_name":"Dewar","link":"http:\/\/www.facebook.com\/alastair.dewar","username":"alastair.dewar","gender":"male","email":"alastair\u0040alastairdewar.co.uk","locale":"en_GB"}
My instinct says it could be a setting within the facebook app, as it wasn't a problem beforehand.
EDIT: https://developers.facebook.com/bugs/412680422092698?browse=search_4f854dc037a2a5d12811839
Thanks for any advice.
Make sure you ask for all the permissions that you need and also remove the app and start again. Make sure you ddon't cache any of the responses as well.
How do you query the API? Graph Explorer or just manually open the link (graph.facebook.com/USER_ID) and pass the auth token generated by the app? Testing with the Graph Explorer won't help you with your problem as permissions etc are different.
As mentioned by Nobita, code helps. This is as much as I can advise considering the amount of data you're giving us.

How to get user's network information using Facebook Graph API? (PHP)

I have been playing with Facebook Graph API around a week, and I still could not find how to get user's network information? I don't know if the Graph API stores user's network; I didn't see such information. Simply, if a user is in "Google" network, may I get the name and the ID of the networks that the user belongs to?
If this is not possible, may I reach the user's secondary email addresses?
Thanks for your help.
Using FQL : the affiliations field of the User table contains this information
Sample call:
https://graph.facebook.com/fql?q=select affiliations from user where uid= 4&access_token=<ACCESS TOKEN>
Sample response:
{
"data": [
{
"affiliations": [
{
"nid": 16777217,
"name": "Harvard",
"type": "college"
},
{
"nid": 50431648,
"name": "Facebook",
"type": "work"
}
]
}
]
}

Categories