问题
I am using twitter4j , i am able to login successfully into my twitter account, but when i am trying to post some thing the following exception is raised.
My Code
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 Exception
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}
回答1:
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());
来源:https://stackoverflow.com/questions/17103234/twitter-4j-no-authentication-challenges-found-relevant-discussions-can-be-found