使用google oauth 2.0和scribe检索博客提要 [英] Retrieve blog feeds using google oauth 2.0 and scribe

查看:127
本文介绍了使用google oauth 2.0和scribe检索博客提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用scribe通过oAuth 2.0连接到谷歌,并成功获得访问令牌。当我试图获取博客时,我总是得到以下错误:

未授权
必须通过身份验证才能使用'默认'用户



以下是代码段:

  GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); 
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET_KEY);
oauthParameters.setScope(http://www.blogger.com/feeds);
oauthParameters.setOAuthToken(ACCESS_TOKEN);
oauthParameters.setOAuthTokenSecret(ACCESS_TOKEN_SECRET); // this is null

BloggerService myService = new BloggerService(blogger);
尝试{
myService.setOAuthCredentials(oauthParameters,new OAuthHmacSha1Signer());
} catch(OAuthException e){
e.printStackTrace();
}
最终网址feedUrl =新网址(http://www.blogger.com/feeds/default/blogs);
Query query = new Query(feedUrl);
Feed resultFeed = myService.getFeed(query,Feed.class);

无法在此处获得提要,并显示上述的未授权错误。

解决方案

Jason相信你已经回答了你的问题。

您不想使用上面的库代码访问博客。使用新的API,并使用OAuth2 https://developers.google.com/blogger /docs/3.0/using#auth



我不确定抄写员是什么,但使用OAuth2时,您需要指出您的应用程序类型,重新构建,它可能是从Web服务器或已安装的应用程序运行的。您确定的是,您可以按照上面链接的java客户端库的相应文档来获取访问令牌并检索数据。


I used scribe to connect to google using oAuth 2.0 and successfully got the access token. When i am trying to get the blogs i always get the below error

Unauthorized Must authenticate to use 'default' user

Below is the code snippet

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET_KEY);
oauthParameters.setScope("http://www.blogger.com/feeds");
oauthParameters.setOAuthToken(ACCESS_TOKEN);
oauthParameters.setOAuthTokenSecret(ACCESS_TOKEN_SECRET); // this is null 

BloggerService myService = new BloggerService("blogger");
try {           
myService.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());          
} catch (OAuthException e) {
e.printStackTrace();
}
final URL feedUrl = new URL("http://www.blogger.com/feeds/default/blogs");
Query query = new Query(feedUrl);
Feed resultFeed = myService.getFeed(query, Feed.class);

Not able to get the feeds here and displays the Unauthorized error as mentioned above.

解决方案

Jason has answered your question, I believe.

You do not want to use the library code above to access blogger. Use the new API, and use OAuth2 https://developers.google.com/blogger/docs/3.0/using#auth

I'm not sure what scribe is, but with OAuth2, you need to indicate what type of application you're building, It might be one that runs from a web server, or an installed application. What's you've determined that, you can follow the appropriate documentation for the java client library linked to above to get the access token and retrieve the data.

这篇关于使用google oauth 2.0和scribe检索博客提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆