开发者

Google OAuth scope parameter to get user's first and last name

开发者 https://www.devze.com 2023-03-07 10:33 出处:网络
Does anybody know how to get the user\'s first and last name from google\'s oauth implementation? I can get only the email address with the scope parameter https://www.googleapis.com/auth/userinfo#em

Does anybody know how to get the user's first and last name from google's oauth implementation?

I can get only the email address with the scope parameter https://www.googleapis.com/auth/userinfo#email

but I can't find how to get first and last name...

anybody knows how to开发者_运维知识库 do that with oauth?


I had the same problem, documentation on the available scopes is nearly impossible to find. I am implementing Oauth 2.0 which is still in the experimental stage with google's api. So, there's not nearly enough documentation.

It seems the scope needed for the name and profile picture is this: https://www.googleapis.com/auth/userinfo.profile

So you'll probably need to use: https://www.googleapis.com/auth/userinfo#profile

By the way, you can make them both in one request

 someauthurl?response_type=code&client_id=123&redirect_url=someurl&scope=somescope1 somescope2 somescope3

Just separate them with a space.


For a list of scopes you could include (separated by spaces) in an oauth initiation url, try http://code.google.com/apis/gdata/faq.html#AuthScopes and try it out.


Here are the URLs you can try:

Authentication

NSString *scope = @"https://www.googleapis.com/auth/userinfo.profile";

Authorization

NSString *urlAuthorization = @"https://www.googleapis.com/oauth2/v1/userinfo?alt=json";

Scope should get you the access token after you have signed in. Then you can use the urlAuth to get a nice JSON string of your profile info such as id, given_name (first name), family_name (last name), etc.

Also refer to http://code.google.com/p/gdata-objectivec-client/ in detail to see sample applications that can also help.


http://www-opensocial.googleusercontent.com/api/people/#USERID# // like g+ profile id


If you are using Login with Google+, have a look at this:

https://developers.google.com/+/api/latest/people

0

精彩评论

暂无评论...
验证码 换一张
取 消