Unable to get User's Email, Address and Mobile phone.

861 views
Skip to first unread message

ne52

unread,
Jan 24, 2011, 1:58:45 PM1/24/11
to RestFB
Hello, I am making a small java application that grabs your User
information from Facebook. I upgraded my libraries to the new 1.6.2
release. The getQuotes() method works great so good job with that.

I found out that, even though the Facebook account I am using has
Mobile phone and Address the methods getMobilePhone() and getAddress()
from class User return null. Same with the getEmail() method.

At first I thought there is some problem with the Facebook
permissions, which shouldn't be since you are logically accessing the
data as "yourself". Nevertheless I changed the privacy settings to
"Everyone" on facebook and I still get null from the said methods.

Then I thought the problem might be at my code but since it's very
simple I can't find anything wrong. (All the other data in User are
fetched fine)

User user = facebookClient.fetchObject("me", User.class);
System.out.println("Address: " + user.getAddress() + "\n");
System.out.println("MobilePhone: " + user.getMobilePhone() + "\n");
System.out.println("Email: " + user.getEmail() + "\n");

So my last thought was that maybe there is something wrong with the
RestFB especially for the Address, MobilePhone and Email. I probably
have something messed up on my code but I made this topic just for
double check. Can any of you, fetch the email, address and mobile
phone info? If yes please let me know.

Thanks.

revetkn

unread,
Jan 24, 2011, 2:21:03 PM1/24/11
to RestFB
Does the RestFB logging output show these fields being returned to
you? Keep in mind that even though you're using an access token for
"you", sometimes that's not good enough - you need to use an access
token for an application to which you've granted these permissions
(whether this makes sense or not is debatable). Check out the
documentation about this on http://restfb.com under the "A note about
the Publish and Delete examples below" heading.

Thanks
Mark

ne52

unread,
Jan 24, 2011, 2:49:29 PM1/24/11
to RestFB
You are right. The restFB logging output doesn't get those info. I
just supposed that since I could get all the other info, i should be
able to get those as well. It seems I need more permissions though,
through a facebook application. I will do some more research. If I am
able to retrieve the info I will post back here.

Thanks again. :)

On Jan 24, 9:21 pm, revetkn <mark.a.al...@gmail.com> wrote:
> Does the RestFB logging output show these fields being returned to
> you?  Keep in mind that even though you're using an access token for
> "you", sometimes that's not good enough - you need to use an access
> token for an application to which you've granted these permissions
> (whether this makes sense or not is debatable).  Check out the
> documentation about this onhttp://restfb.comunder the "A note about

Jason Peltzer

unread,
Jan 24, 2011, 3:04:58 PM1/24/11
to res...@googlegroups.com
If you check out the examples on http://restfb.com/ you'll need to fetch the user like so:

User userWithMetadata = facebookClient.fetchObject("me", User.class, Parameter.with("metadata", 1));

which is basically: https://graph.facebook.com/me?access_token=XXX_ACCESS_TOKEN_XXX&metadata=1
What you are currently doing (I assume) is https://graph.facebook.com/me?access_token=XXX_ACCESS_TOKEN_XXX which is the equivalent of:

User user = facebookClient.fetchObject("me", User.class, new Parameter[] {});

If you haven't gotten the right set of extended permissions from your app: http://developers.facebook.com/docs/authentication/permissions the json will come back with something like this, and the description will tell you which extended permission you need:

{
   "name": "mobile_phone",
   "description": "The user's mobile phone number. Requires the `user_mobile_phone` permission. A JSON string."

ne52

unread,
Jan 24, 2011, 4:10:55 PM1/24/11
to RestFB
Okay I must confess I got a bit confused now.

What I am doing is that I follow this guide:

"It's really easy with the Facebook Graph API. Sign in to Facebook and
navigate to the Graph API documentation. Click on the "Example" link
that shows Graph API JSON data. You should see an access_token
parameter in your URL bar. That's it! Just copy and paste it into your
code."

I get my accessToken and i pass it in my java desktop application. (I
haven't made an application on Facebook).

FacebookClient facebookClient = new
DefaultFacebookClient(accessToken);
User user = facebookClient.fetchObject("me", User.class,
Parameter.with("metadata", 1));

The method getWork() requires user_work_history permission and
getMobilePhone() requires user_mobile_phone permission. I have never
asked for any of those permissions on my code. Why am I able to get
result from user.getWork(); and not from user.getEmail(),
getMobilePhone() and getAddress();?
According to http://restfb.com/ I only need special permissions to
post and delete.

How can I ask for the user_mobile_phone permission on my code?

Do I really have to create a facebook application like revetkn said?


Thanks for the help

On Jan 24, 10:04 pm, Jason Peltzer <pelt...@gmail.com> wrote:
> If you check out the examples onhttp://restfb.com/you'll need to fetch the
> user like so:
>
> User userWithMetadata = facebookClient.fetchObject("me", User.class,
> Parameter.with("metadata", 1));
>
> which is basically:https://graph.facebook.com/me?access_token=XXX_ACCESS_TOKEN_XXX&metad...
> What you are currently doing (I assume) ishttps://graph.facebook.com/me?access_token=XXX_ACCESS_TOKEN_XXXwhich is the
> equivalent of:
>
> User user = facebookClient.fetchObject("me", User.class, new Parameter[]
> {});
>
> If you haven't gotten the right set of extended permissions from your app:http://developers.facebook.com/docs/authentication/permissionsthe json will
> come back with something like this, and the description will tell you which
> extended permission you need:
>
> {
>    "name": "mobile_phone",
>    "description": "The user's mobile phone number. Requires the
> `user_mobile_phone` permission. A JSON string."
>
>
>
>
>
>
>
> }
> On Mon, Jan 24, 2011 at 2:49 PM, ne52 <ne52.uop...@gmail.com> wrote:
> > You are right. The restFB logging output doesn't get those info. I
> > just supposed that since I could get all the other info, i should be
> > able to get those as well. It seems I need more permissions though,
> > through a facebook application. I will do some more research. If I am
> > able to retrieve the info I will post back here.
>
> > Thanks again. :)
>
> > On Jan 24, 9:21 pm, revetkn <mark.a.al...@gmail.com> wrote:
> > > Does the RestFB logging output show these fields being returned to
> > > you?  Keep in mind that even though you're using an access token for
> > > "you", sometimes that's not good enough - you need to use an access
> > > token for an application to which you've granted these permissions
> > > (whether this makes sense or not is debatable).  Check out the
> > > documentation about this onhttp://restfb.comunderthe "A note about

Marcel Stör

unread,
Jan 24, 2011, 4:31:14 PM1/24/11
to res...@googlegroups.com
On 24.01.11 22:10, ne52 wrote:
[...]

> Do I really have to create a facebook application like revetkn said?
[...]

Yes, as far as I understand your use case you have to. There are various
types of tokens and each token represents a set of permissions.

I really recommend you read through
http://developers.facebook.com/docs/authentication/ as you'll be
struggling time-and-time again with permission issues if it ain't done
properly from the beginning.

Another helpful site in terms of (introductory) explanations and tools
is http://www.takwing.idv.hk/tech/fb_dev/index.php

Cheers,

--
Marcel St�r, http://www.frightanic.com
Couchsurfing: http://www.couchsurfing.com/people/marcelstoer
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

ne52

unread,
Jan 27, 2011, 9:27:22 AM1/27/11
to RestFB
I found the problem. I created an application and i got all the
possible permissions. Now getEmail() returns the email address of the
user correctly and not Null.

In case anyone has problems with getAddress() and getMobilePhone(),
this is because Facebook has temporarly disabled the permissions
"user_address" and "user_mobile_phone" which you need to have in your
application to get that info. So for now it is not possible to get the
address and mobile phone of a user through the RestFB but it's not a
problem of RestFB.

Source: http://developers.facebook.com/blog/post/447

Cheers

On Jan 24, 11:31 pm, Marcel Stör <mar...@frightanic.com> wrote:
> On 24.01.11 22:10, ne52 wrote:
> [...]> Do I really have to create a facebook application like revetkn said?
>
> [...]
>
> Yes, as far as I understand your use case you have to. There are various
> types of tokens and each token represents a set of permissions.
>
> I really recommend you read throughhttp://developers.facebook.com/docs/authentication/as you'll be
> struggling time-and-time again with permission issues if it ain't done
> properly from the beginning.
>
> Another helpful site in terms of (introductory) explanations and tools
> ishttp://www.takwing.idv.hk/tech/fb_dev/index.php
>
> Cheers,
>
> --
> Marcel St r,http://www.frightanic.com
Reply all
Reply to author
Forward
0 new messages