如何使用oauth获取电子邮件ID

时间:2014-08-29 14:00:57

标签: java security oauth yahoo scribe

我正在尝试使用以下代码获取用户个人资料信息。我正在使用scribe来获取信息。我能够获得familyName和givenName等,但它不会返回我的电子邮件ID。

我正在使用以下代码:

OAuthRequest request = new OAuthRequest(
    Verb.GET,
    "https://social.yahooapis.com/v1/me/guid? format=xml"
); 
service.signRequest(accessToken, request);
request.addHeader("realm", "yahooapis.com"); 
Response response = request.send();

这是我得到的回应:

{
    "profile": {
        "guid":"CGGT5LNT7NXGFK64QW7FQN5UQM",
        "ageCategory":"A",
        "familyName":"gto",
        "givenName":"CTSDemo",
        "image": {
            "height":192,
            "imageUrl":"https://s.yimg.com/dh/ap/social/profile/profile_b192.png",
            "size":"192x192",
            "width":192
        },
        "intl":"us",
        "jurisdiction":"us",
        "lang":"en-US",
        "location":"Bangalore",
        "memberSince":"2014-08-03T08:23:27Z",
        "nickname":"CTSDemo",
        "notStored":false,
        "nux":"3",
        "profileMode":"PUBLIC",
        "profileStatus":"ACTIVE",
        "profileUrl":"http://profile.yahoo.com/CGGT5LNT7NXGFK64QW7FQN5UQM",
        "updated":"2014-08-29T12:00:44Z",
        "isConnected":false,
        "profileHidden":false,
        "bdRestricted":true,
        "profilePermission":"PUBLIC",
        "uri":"https://social.yahooapis.com/v1/user/CGGT5LNT7NXGFK64QW7FQN5UQM/profile",
        "cache":true
    }
}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案!

您需要在雅虎更改您的应用程序的权限。 enter image description here

网址,提供用户信息:https://social.yahooapis.com/v1/user/me/profile

不要忘记添加标题授权:Bearer [your_access_token]