Facebook - "Cannot Query Users by Their Username" Solution

Facebook - Cannot query users by their username solution

Since v2.0 of the API, you are not supposed to use usernames at all - and that´s why you can´t query users by their username anymore. The only way to get access to data of a user is by authorizing that user and using the /me endpoint.

Main rule: Forget about users who did not authorize your App, you are not supposed to get any data of those for privacy reason.

Is it possible to get a users basic profile data using facebook api with their username

No, you can´t use the username anymore. If you try to get data of a user with the username, you will get the following error message:

Cannot query users by their username

facebook userid from username in excel power query

Looking around the Power Query Facebook connector and the Facebook Graph API reference I can't find any obvious way to look up user id's from the username.

http://findmyfbid.com/failure indicates that a search engine had to index the public usernames in order to find the id. You can open a page like https://www.facebook.com/Code.org/ in your browser and muck through the HTML and find the username yourself, assuming the page is still public.

On the other hand, findmyfbid.com has already solved this problem. Here's how to query against their website directly using a custom Power Query function FindId:

let
// Assume you've already URL-encoded the id
FindId = (id as text) as text =>
let
Source = Web.Contents("http://findmyfbid.com/", [
Content = Text.ToBinary("url=" & id),
Headers = [#"Content-Type"= "application/x-www-form-urlencoded"]
]),

// Web.Page can't POST directly, so force Web.Contents to execute the POST
WebPage = Web.Page(Binary.Buffer(Source)),

// Hopefully findmyfbid.com doesn't change their HTML layout
DrillDown = WebPage[Data]{0}
{[Name="HTML"]}[Children]
{[Name="BODY"]}[Children]
{[Name="DIV"]}[Children]
{[Name="DIV"]}[Children]
{[Name="CODE"]}[Children]
{[Kind="Text"]}[Text]
in
DrillDown,
ExampleCodeOrg = FindId("code.org")
in
ExampleCodeOrg

And you find that Code.org has an Id of 309754825787494.

Get Facebook User ID from app-scoped User ID

there's no (simple/obvious) possibility to get a real user id based on an app-scoped user id.

How do I get my own Facebook App-Scoped User Id with v2.0 of Graph?

You can use the graph explorer tool:

https://developers.facebook.com/tools/explorer/?method=GET&path=me

The tool has a dropdown list at the top of the page where you can select an app of which you are a developer. Choose your app in this list, then choose "Get Access Token", then press "Submit" to submit the default "/me" query.

The id field of the result will be your app-scoped user ID in this app.



Related Topics



Leave a reply



Submit