CQM*_*CQM 5 authentication twitter android jtwitter oauth-2.0
您好我使用JTwitter函数难以使用我的twitter应用程序进行身份验证.我总是得到一个"TwitterException"
这是我的方法
OAuthSignpostClient oauthClient = new OAuthSignpostClient(consumerKey,
privateKey, "oob");
Run Code Online (Sandbox Code Playgroud)
一)我不知道"OOB"值应该是什么,它是"callbackURL",并在我的Twitter应用程序,它说"callBack URL: none" ,所以我试图把"none","None"和null 在那里"oob",没有不同的结果.
然后其余的是样板
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse(oauthClient.authorizeUrl().toString()));
startActivity(i);
// get the pin
String v = oauthClient.askUser("Please enter the verification PIN from Twitter");
oauthClient.setAuthorizationCode(v);
// Store the authorisation token details for future use
String[] accessToken = oauthClient.getAccessToken();
// Next time we can use new OAuthSignpostClient(OAUTH_KEY, OAUTH_SECRET,
// accessToken[0], accessToken[1]) to avoid authenticating again.
EditText twitterText = (EditText)findViewById(R.id.twitterText);
twitterText.getText();
// Make a Twitter object
Twitter twitter = new Twitter(null, oauthClient);
// Print Daniel Winterstein's status
//System.out.println(twitter.getStatus("winterstein"));
// Set my status
twitter.setStatus(twitterText.getText());
Run Code Online (Sandbox Code Playgroud)
在这一点上,我只是不确定如何使这项工作.希望我对它更加冗长,但它与身份验证有关.我见过的在线内容没有帮助
试试这个作为你的回调网址:
OAuthSignpostClient oauthClient =
new OAuthSignpostClient(consumerKey, privateKey, "callback://twitter");
Run Code Online (Sandbox Code Playgroud)
记得!后:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
Run Code Online (Sandbox Code Playgroud)
请执行下列操作
覆盖 onResume()以获取验证码
protected void onResume() {
super.onResume();
if (this.getIntent()!=null && this.getIntent().getData()!=null){
Uri uri = this.getIntent().getData();
if (uri != null && uri.toString().startsWith("callback://twitter")) {
//Do whatever you want
//usually use uri.getQueryParameter(someString);
//test what could be someString using Log.v("",uri.toString());
//you want the Authorization code which is a couple of numbers
//so you could use oauthClient.setAuthorizationCode(v);
//and finally initialise Twitter
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用uri.getQueryParameterNames()获取参数String名称.
@BobVork
我只想补充一点,您需要在Twitter应用的"设置"标签中设置回调网址(在twitter.com上).
你在场上放什么都没关系,但如果它是空的,回调网址将不起作用.
| 归档时间: |
|
| 查看次数: |
1413 次 |
| 最近记录: |