android – 方法retrieveRequestToken引发“与服务提供商通信失败:null”

android – 方法retrieveRequestToken引发“与服务提供商通信失败:null”,第1张

概述我使用twitter4j从我的应用程序发送推文.当我调用方法retrieveRequestToken时,我得到错误“与服务提供商的通信失败:null”. public static void askOAuth(Context context) { try { // Use Apache HttpClient for HTTP messaging consum 我使用twitter4j从我的应用程序发送推文.当我调用方法retrIEveRequestToken时,我得到错误“与服务提供商的通信失败:null”.
public static voID askOAuth(Context context) {    try {        // Use Apache httpClIEnt for http messaging        consumer = new CommonshttpOAuthConsumer(CONSUMER_KEY,CONSUMER_SECRET);        provIDer = new CommonshttpOAuthProvIDer(                "https://API.twitter.com/oauth/request_token","https://API.twitter.com/oauth/access_token","https://API.twitter.com/oauth/authorize");        String authUrl = provIDer.retrIEveRequestToken(consumer,CALLBACK_URL);        Toast.makeText(context,"Authorize this app!",Toast.LENGTH_LONG).show();        context.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(authUrl)));    } catch (Exception e) {        Log.e(APP,e.getMessage());        Toast.makeText(context,e.getMessage(),Toast.LENGTH_LONG).show();    }}

谢谢.

解决方法@H_419_9@ 如果这是ICS,我强烈建议不要使用StrictMode.enableDefaults ;.

ICS不允许在UI线程中发生http请求,所以当你这样做时,你会得到这个错误.

要解决这个问题,请做provIDer.retrIEveRequestToken(consumer,CALLBACK_URL);在后台线程以及provIDer.retrIEveAccesstoken(consumer,verifIEr);.

资料来源:http://code.google.com/p/oauth-signpost/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=71

总结

以上是内存溢出为你收集整理的android – 方法retrieveRequestToken引发“与服务提供商通信失败:null”全部内容,希望文章能够帮你解决android – 方法retrieveRequestToken引发“与服务提供商通信失败:null”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1131650.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存