gpt4 book ai didi

java - twitter4j 未找到身份验证挑战

转载 作者:行者123 更新时间:2023-11-30 03:58:00 25 4
gpt4 key购买 nike

几天来一直在尝试使用 twitter4j 发布一条推文,但没有成功,我想要做的是让一个人在一轮结束时通过应用程序在他们的时间轴上发布他们的新最高分。这是我的代码

          @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tweetr);
Button tweetr = (Button)findViewById(R.id.tweetr);

//create a new twitter configuration using user details
tweetTwitter = new TwitterFactory().getInstance();
tweetTwitter.setOAuthConsumer(TWIT_KEY, TWIT_SECRET);


//create a twitter instance
// tweetTwitter = new TwitterFactory(twitConf).getInstance();



tweetr.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {


dt.execute();

}
});



}


public class TweetTask extends AsyncTask<Object, Void, String> {
@Override
protected String doInBackground(Object... values) {
/* try {
//requestToken = tweetTwitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
*/
try {
requestToken = tweetTwitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
String authUrl = requestToken.getAuthenticationURL();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return null;
}


@Override
protected void onPostExecute(String result) {
Log.d("URI", "DONE");
super.onPostExecute(result);
}




}



@Override
protected void onResume() {
super.onResume();
final Uri uri = getIntent().getData();
if(uri != null ){

Log.d("URI", uri.toString());

Thread th = new Thread(){
public void run(){
try {
String verifier = uri.getQueryParameter("oauth_verifier");
String oauthToken = uri.getQueryParameter("oauth_token");

RequestToken reqToken = tweetTwitter.getOAuthRequestToken(oauthToken,verifier);


AccessToken accessToken = tweetTwitter.getOAuthAccessToken(reqToken);
String token = accessToken.getToken(), secret = accessToken.getTokenSecret();

} catch (TwitterException ex) {
Log.e("Main.onNewIntent", "" + ex.getMessage());
}


}};
th.start();
}else
Log.d("URI", "FAILED");


}

这是我打印出来的错误

10-23 15:35:18.661: D/TWIT ER(2392): No authentication challenges foundRelevant discussions can be found on the Internet at:

最佳答案

引用javadoc Twitter4J的

In order to get access acquire AccessToken using xAuth, you must apply by sending an email to api@twitter.com — all other applications will receive an HTTP 401 error.

关于java - twitter4j 未找到身份验证挑战,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13041146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com