gpt4 book ai didi

android - Twitter 4j 未发现身份验证挑战,相关讨论可在 internet Exception 中找到

转载 作者:太空狗 更新时间:2023-10-29 14:20:49 25 4
gpt4 key购买 nike

我正在使用 twitter4j ,我能够成功登录到我的 Twitter 帐户,但是当我尝试发布一些内容时,出现了以下异常。

我的代码

try
{

Bitmap bmpFinal = getBitmapFromURL(Imagename.trim());
Log.d("ImagePath",Imagename);

Configuration conf = new ConfigurationBuilder()
.setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET)
.setOAuthAccessToken(access_token)
.setOAuthAccessTokenSecret(access_token_secret)
.setMediaProviderAPIKey("320954b8bf13ffd7463a4dbe667b9dd2")
.build();

Uri tempUri = getImageUri(getApplicationContext(), bmpFinal);

File finalFile = new File(getRealPathFromURI(tempUri));// THIS IS IMPORTANT. TWITPIC NEEDS THE ACTUAL / ABSOLUTE PATH OF THE IMAGE. JUST THE URI DOES NOT WORK!!!!

ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.TWITPIC);

String url = upload.upload(finalFile);
Log.e("TWITTER URL RESPONSE", url);
Log.d("TWITTER URL RESPONSE", url);
// END OF FIRST STEP:

// SECOND STEP IS TO UPLOAD TO TWITTER

ConfigurationBuilder builder = new ConfigurationBuilder();

builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

AccessToken accessToken = new AccessToken(access_token, access_token_secret);
Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

String finalStatusWithURL = null;

if (status.trim().length() > 0) {

finalStatusWithURL = status + ":\n " + url;

} else {
finalStatusWithURL = url;
}
twitter4j.Status response = twitter.updateStatus(finalStatusWithURL);
Log.e("TWITTER RESPONSE", response.getText());
}
catch(Exception e)
{
Log.d("Exception ",""+e);
}
return null;
}

Logcat 异常

06-14 12:51:31.117: D/Exception(3302): No authentication challenges found
06-14 12:51:31.117: D/Exception(3302): Relevant discussions can be found on the Internet at:
06-14 12:51:31.117: D/Exception(3302): http://www.google.co.jp/search?q=ea09dc6d or
06-14 12:51:31.117: D/Exception(3302): http://www.google.co.jp/search?q=051c1797
06-14 12:51:31.117: D/Exception(3302): TwitterException{exceptionCode=[ea09dc6d-051c1797 0237e8c8-9e66d70f], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.2}

最佳答案

    twitter = new TwitterFactory().getInstance();
//Retrieve access token
authProvider.retrieveAccessToken(authConsumer,verifier);

//Initialize access token of twitter4j
AccessToken mAccessToken = new AccessToken( authConsumer.getToken(),authConsumer.getTokenSecret());

//optional to save it for future use
ProjectUtil.setAccessTokenTwitter((MainActivity)mScreen, mAccessToken.getToken());
ProjectUtil.setAccessSecretTwitter((MainActivity)mScreen, mAccessToken.getTokenSecret());

//Set twitter4j.Twitter Oauth
twitter.setOAuthConsumer(AppConstants.CONSUMER_KEY, AppConstants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(mAccessToken);
//message
StatusUpdate ad=new StatusUpdate("my messgae");

//Image from sdcard
File file = new File(Environment.getExternalStorageDirectory()+"/myimage.png");
InputStream inputStream = new FileInputStream(file);
ad.setMedia("myMedia",inputStream);

twitter4j.Status response = twitter.updateStatus(ad);



Log.d("Status", response.getText());

关于android - Twitter 4j 未发现身份验证挑战,相关讨论可在 internet Exception 中找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17103234/

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