Facebook Graph API Limited User Data Set - facebook-graph-api

I'm a beginner with Facebook Graph API.
I have a Facebook application and I seem to be able to use the API via my HTTP client.
The problem I'm having is that the user data I'm receiving is very limited. I'm just getting two fields, name and id (here's an example with made-up data to show the JSON format:
{
"name": "John Smith",
"id": "238475638375462"
}
I know there are a lot more fields, so where are they? Is it possible that because my application isn't fully approved by Facebook yet that they're limiting my scope?
Here's the API endpoint documentation:
https://developers.facebook.com/docs/graph-api/reference/user/

It turns out the solution is quite simple. The details are buried in the API documentation. It's really just a matter of "choosing fields" as explained here.
If I want fields other than the default name and id, I must list them in the query string. Here's an example
https://graph.facebook.com/v2.6/238475638375462?fields=id,name,birthday,email&access_token=BIG_LONG_ACCESS_TOKEN
Gives me:
{
"id": "238475638375462",
"name": "John Smith",
"birthday": "10/10/1990",
"email": "user#example.com"
}
Concerns about scoping are also quite valid here. I found the Facebook Access Token Tool useful to confirm my scopes and keep me headed in the right direction.

Related

How to determine why a facebook page URL will not return a facebook id?

For the most part, using the graph api, passing in a Facebook page's encoded URL returns the normal facebook id.
For instance, using the Graph API Explorer and passing in https%3A%2F%2Fwww.facebook.com%2Fkendalljenner returns
{
"name": "Kendall Jenner",
"id": "173567062703796"
}
However, for some (pretty rare) FB pages, like http%3A%2F%2Fwww.facebook.com%2Fmargotrobbie, I get
{ "id": "http://www.facebook.com/margotrobbie" }
The question, Why do some Facebook urls not return their Facebook page id through graph api?, suggests that the issue may be that the page is restricted somehow (like for alcohol content). I believe this may be the case, because the Harley Quinn videos in the posts are a bit graphic, but I searched all the info for the page and it doesn't say anything about the content being restricted. In addition, I am using a User access token that is allowed to see the page via normal FB web interface without any apparent restriction.
BTW, for anyone who hasn't seen this before, the id set to the url seems to be the result when facebook doesn't know anything about the URL. Obviously this shouldn't be the case for facebook's own URL.
Not sure what the reason for the apparent difference with the two page URLs indicated, but I did solve the underlying problem of getting the facebook id of the page!
First of all, I had tried the process described here: How to get page id of facebook page, however it wasn't working for me. In my effort to permute all options, I had changed the access token to a "user access token". Turns out, you HAVE to have an "application access token" as is well-documented in said article.
Thanks to CBroe for making me question how I was calling the API...no matter how long I was calling it this way.

Amazon Alexa Skills Kit: How do you link with external app account / userId

In an Amazon alexa skill request, there is a userId. I'm trying to understand what this is and if there is some reference for it because I want to link and Amazon Echo user account with an account in my own app and to do this I would have to have some kind of static userId to work with.
Example request:
{
"version": "1.0",
"session": {
"new": false,
"application": {
"applicationId": "amzn1.echo-sdk-ams.app.[unique-value-here]"
},
"sessionId": "session1234",
"attributes": {},
"user": {
"userId": null //IS THERE A DETAILED REFERENCE OF THIS SOMEWHERE?
}
},
"request": {
"type": "IntentRequest",
"requestId": "request5678",
"intent": {
"name": "MyColorIsIntent",
"slots": {
"Color": {
"name": "Color",
"value": "blue"
}
}
}
}
}
Great question.
Short answer: You're going to have to build your own pairing between your 3rd party user and the Alexa UserID. There's no built-in support into the Alexa Skills SDK that lets you associate an Alexa UserID with your user ID. You're going to have to create a specific voice intent that associates Alexa UserIDs to your Users DB.
Longer answer: Let's start by talking about that Alexa UserID you get in each request. The Alexa UserID you get is an LWA (Login-With-Amozon) user ID. It's primary purpose to allow Alexa Skills to reliably detect repeating users.
So what doesn't work? The issue you're going to run into is that the LWA userId is always anonymized to each Alexa app. That's important because it makes sure users aren't tracked; but it also prevents you from associating the Alexa userID with your own LWA userID.
From the "Login with Amazon - Developer Guide" (page 10)
Every company that creates websites or apps for Login with Amazon gets
the same user_id for a customer. However, when a customer logs in to
another company's app or site, the user_id will be different. This is
so user_id cannot be used to track customers across the Web.
What I'm trying to say is that you can't just implement LWA in iOS, Android or Web apps and expect to get the same LWA userId for an account as you would get as an Alexa userID. For example, if you implemented LWA on your Android app an had foo#bar.com user login to their Amazon account you might get amzn1.account.123456 as a userID, but when that same foo#bar.com user talks to their paired Echo you'll get a amzn1.account.98765 or any other totally different userId. I actually wasted two days building this architecture which is how I know it doesn't work.
So what does work? A voice-centric variation of Pin authentication seems best.
Let's look at another space of apps with a similar problem: TV apps (xbox, android TV, etc). A lot of those apps require you to login in order to get access to content (e.g. hulu, netflix, etc). But using a remote control to enter a username and password is just plain old bad UX. So what did we do for TV apps? Users go to myService.com/tv, login to their account and get a special short, numerical and time-sensitive pin code they can input to their TV.
When I was implementing an Alexa Skill we decided to take a similar approach. Users would login into our website, iOS app or Android app, go to a dedicated Echo page and then get a pin code. The on-screen instructions that would read something like this:
Go to your Echo and say:
'Launch foo'
'My pin is one two three four'
In our foo skill we have a PairingIntent intent listen to "my pin is {one two three four|pinCode}" sample utterance. After receiving a PairingIntent we'd check if that pin code was valid and if so associated that Alexa userID with our own users DB. If the pin was valid Echo would say something like "Oh, hi there bob! You now have access to all your awesome stuff.". If the pin code wasn't valid alexa would prompt users to try again.
Hopefully this makes sense. There are other options to associate 3rd party accounts with Alexa Skills but this voice-pin approach is the simplest.
I don't know why the original answer has been deleted but Amazon now lets you link an Alexa User with a user in your system. Here's the announcement.
How End Users Set Up Account Linking for a Skill
Users link their accounts using the Amazon Alexa app. Note that users
must use the app. There is no support for establishing the link solely
by voice.
Users normally start the process when initially enabling your skill in
the app:
In the Alexa app, the user enables the skill.
The app displays your login page right within the app, using the authorization URL you provide when registering your skill on the
developer portal. When the companion app calls this URL, it includes
state, client_id, and scope as query string parameters.
The state is used by the Alexa service during the account linking process. Your page needs to keep track of this value, as you must
pass it back later.
The client_id is defined by you. Your login page can use this to determine that the request came from your Alexa skill.
The scope is an optional list of access scopes indicating the level of access requested. You define the set of scopes to support when
enabling account linking for your skill.
The user logs in using their normal credentials for your site.
Your service authenticates the user and then generates an access token that uniquely identifies the user in your system.
Your service redirects the user to an Amazon-specific URL and passes along the state, access_token, and token_type in the URL
fragment.
The Alexa service validates the returned information and then saves the access_token for the Alexa user.
At this point, the skill is enabled, the user’s Alexa account is
linked to the account in your service, and the skill is ready to be
used.
The userid given to the Alexa skill is guaranteed to be unique per user. It is anonymized according to the developer ID, so it will be the same across all of your skills, but it will differ from developer to developer. There is no way to explicitly link it back to any real world ID. You have to do that yourself.
My general recommendation is to do it like Firefox sync. If both your Alexa skill and your application share a back-end, then when a user wants to sync from Alexa, generate a 4-character sync code, store it in the back end, read it to the user, and tell them to go to the web site and type it in. On the web site, when they give a sync code, match it up and form your link between the two.
I talk about this in a little more detail in my book, but that's the gist of it.
In an Amazon alexa skill request i am trying to bind it with username.
As you can not get an actual user name. But, to be more complete there are different ways that are used to do what you are trying to to. It would depend on what you're skill is trying to accomplish to know which is the approach for you.
Your options are:
Linking a user name in your system to the Alexa user. In that case you do not get a user name. You get a token, and you would link the user name together in your system using that token. Read: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/linking-an-alexa-user-with-a-user-in-your-system
If what you're trying to do is just to uniquely identify one user from another, but you don't care or need any specific information on that user. The request comes with a user (session.user.userId). It's a random character string that will identify that user for all requests they send, but tells you nothing about them. Read: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference
You could have an intent which would be something like "SetUser" and let the user speak to you the username they would like. Then you could use #2 above to link them together in some data storage somewhere. I don't know if Amazon supports this route though as it would really be a way to circumvent #1. So, it depends on what you're trying to do. If you need personal information on the user use #1. If you just need to know that it's some user vs another user use #2.

How to retrieve analytics on a post made by my Facebook App

I have a Facebook app that posts pictures to users' feeds using the graph API. I want to find out how many other Facebook users view each picture that gets posted. I have tried using the insights API, but it only returns empty data. For example, suppose a post has the ID:
100003858263437_217258205079453
If I visit:
https://graph.facebook.com/100003858263437_217258205079453/insights?access_token=ACCESS_TOKEN
The returned data is empty:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/100003858263437_217258205079453/insights?access_token=ACCESS_TOKEN&since=-86400&until=0",
"next": "https://graph.facebook.com/100003858263437_217258205079453/insights?access_token=ACCESS_TOKEN&since=0&until=86400"
}
}
It seems from the Insights documentation that getting insights on a particular post may not be possible. Anyone know how to get Insights for a post made by an application?
Correct, there is no pulling insights for User accounts. You can only pull insights for pages, applications, and domains the user owns if you have the read_insights permission

tracking facebook like counts for many facebook pages

Scenario:
I'm looking to track the "like counts" for 100's to 1,000's of facebook pages. Currently I have a google spreadsheet that is setup with graph api that this post mentions.
I'm looking to automate the process a bit more if possible.
Here are my current steps:
find the fb business page address https://facebook.com/businessnamehere
locate the fb page id and enter it in the worksheet
the # of fans is populated for businesses that allow access through graph api
Couple Issues:
Some business pages block access to the basic info and the following error is given:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
Is there any other way to pull the "like count" besides pulling up the actual fb business page and viewing the "like count"?
The worksheet only pulls from the Page ID.
Is there any way to pull the "like count" from the facebook url only without needing to gather the fb page id?
Any help would be appreciated. Thanks.
There are pages which might have geographical restrictions or age restrictions or even be locked viewable only to administrator, maybe this is the root cause of your problem (Stated here in introduction).
As for your second question, you can do graph request with the name on the business listed after "facebook.com/". For example you can find likes on facebook.com/ign using
$info = $facebook->api('/ign','GET');
$likes = $info['likes'];
instead of using page ID as
$info = $facebook->api('/59685491632','GET');
$likes = $info['likes'];
where 59685491632 is IGN's page ID.

Getting which users shared a post

With the graph api, when I query for the feed of a user or page, there are some posts that have been shared by users, and I can see the data about the number of shares within the data section of one entity:
"shares": {
"count": 2
},
When browsing facebook, on that post, when I click on the icon that represents "show shares", something pops up that lets me see some users that shared the post, according to the comment "You can see only shares that are public or from friends."
So is there a way to get the user data from the shares with the graph api?
The API doesn't provide information about users who have shared a post / link. Its probably something they will add in the future, but it's not possible at the moment. Your best bet for this information is to scrape the UI to get this information, but you will run into lots of issues and it's probably not worth the effort.
Facebook does give information on who Likes and Comments on posts however, if its any consolation.