kartal
kartal

Reputation: 18086

Get userid in facebook from its e-mail using c#

I am using Facebook API how i can get userid in facebook from its mail ?

I am using Facebook.dll

Upvotes: 0

Views: 1386

Answers (3)

user1120658
user1120658

Reputation: 11

dynamic result = fb.Get("/search", parameters);

should be changed into something like:

dynamic result = fb.Get("/me", parameters);

Upvotes: 1

prabir
prabir

Reputation: 7794

Here is how you would do it using Facebook C# SDK.

var fb = new FacebookClient("access_token");
dynamic parameters = new ExpandoObject();
parameters.q = "[email protected]";
parameters.type = "user";
dynamic result = fb.Get("/search", parameters);

If user is found you will get exactly one result.

if(result.data.Count == 1){
    var uid = result.data[0].id;
}

Upvotes: 0

Maggie
Maggie

Reputation: 8081

Using a Search API, you can query all publicly available information. That means, you can get user ID if the user allowed his e-mail address to be public.
You would issue a query something like:

 https://graph.facebook.com/[email protected]&type=user&access_token=... 

The JSON response would be:

{
      "data": [
        {
         "name": "Firstname Lastname"
         "id": "123456799"
        }
   ]
} 

If the user's address is not public, you will get an empty data.

I'm not aware if there is an implementation for this in C#, but you can easily make one.

Upvotes: 1

Related Questions