Токен доступа не создается при использовании библиотеки писцов для публикации изображения в Twitter
OAuthService oAuth = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey("6JyIkj71ZqG4wk3YF0Y4hw") // REPLACE WITH YOUR OWN!!!
.apiSecret("sJl9aRVqlEt7nxlKvpMVK6tLULz5FSQ2KUOW0yie4") // REPLACE WITH YOUR OWN!!!
.callback(TwitterApp.CALLBACK_URL) // REPLACE WITH YOUR OWN!!!
.build();
Log.e("hi","hi");
Token requestToken = oAuth.getRequestToken();
if(requestToken!=null){
Log.e("has requestToken","has");
}
Uri uri = Uri.parse(TwitterApp.CALLBACK_URL);
String verifier = uri.getQueryParameter("oauth_verifier");
Verifier v = new Verifier(verifier);
// Token accesstoken= TwitterApp.mAccessToken;
if(v!=null){
Log.e("verifier created","created");
}
Token accesstoken=oAuth.getAccessToken(requestToken, v);
Log.e("raw resp", accesstoken.getRawResponse());
// Log.e("access",accesstoken.toString());
// BUILD OAUTH REQUEST & SIGN IT RIGHT AWAY (OTHERWISE MULTIPART FORM MAY PREVENT SIGNING)
if(accesstoken!=null){
Log.e("hello","hhello");
Log.e("access token","hi"+accesstoken.toString());
OAuthRequest request = new OAuthRequest(Verb.POST, "https://upload.twitter.com/1/statuses/update_with_media.json");
oAuth.signRequest(accesstoken, request); // ENTER USER'S ACCESS TOKEN
// ADD MULTIPART FORM
try
{
MultipartEntity entity = new MultipartEntity();
entity.addPart("status", new StringBody("insert vacuous statement here")); // THIS IS THE TWITTER MESSAGE
entity.addPart("media", new FileBody(new File("/storage/sdcard0/HelloAlbum/1361964305003.jpg"))); // THIS IS THE PHOTO TO UPLOAD
ByteArrayOutputStream out = new ByteArrayOutputStream();
entity.writeTo(out);
request.addPayload(out.toByteArray());
request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());
}
catch (UnsupportedEncodingException e) {e.printStackTrace();}
catch (IOException e) {e.printStackTrace();}
// SEND REQUEST
try {JSONObject response = new JSONObject (request.send().getBody());}
catch (JSONException e) {Log.e("TOUR_APP_TAG", "JSONException Thrown: " + e.getMessage());}
}
Logcat:
03-01 13:14:52.582: E/AndroidRuntime(5810): FATAL EXCEPTION: main
03-01 13:14:52.582: E/AndroidRuntime(5810): java.lang.IllegalArgumentException: Must provide a valid string as verifier
03-01 13:14:52.582: E/AndroidRuntime(5810): at org.scribe.utils.Preconditions.check(Preconditions.java:80)
03-01 13:14:52.582: E/AndroidRuntime(5810): at org.scribe.utils.Preconditions.checkNotNull(Preconditions.java:27)
03-01 13:14:52.582: E/AndroidRuntime(5810): at org.scribe.model.Verifier.<init>(Verifier.java:22)
03-01 13:14:52.582: E/AndroidRuntime(5810): at com.android.twitter.TwitterActivity$1.onComplete(TwitterActivity.java:278)
03-01 13:14:52.582: E/AndroidRuntime(5810): at com.twitter.android.TwitterApp$1.handleMessage(TwitterApp.java:244)
03-01 13:14:52.582: E/AndroidRuntime(5810): at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 13:14:52.582: E/AndroidRuntime(5810): at android.os.Looper.loop(Looper.java:137)
03-01 13:14:52.582: E/AndroidRuntime(5810): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-01 13:14:52.582: E/AndroidRuntime(5810): at java.lang.reflect.Method.invokeNative(Native Method)
03-01 13:14:52.582: E/AndroidRuntime(5810): at java.lang.reflect.Method.invoke(Method.java:511)
03-01 13:14:52.582: E/AndroidRuntime(5810): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-01 13:14:52.582: E/AndroidRuntime(5810): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-01 13:14:52.582: E/AndroidRuntime(5810): at dalvik.system.NativeStart.main(Native Method)
I am using the above code to post image to the twitter.I used scribe library to complete this task.
Я получаю (Requesttoken и Verifier), но не получаю "accesstoken".
Я работал над этим в течение последних двух дней, но не нашел никакого решения.
Пожалуйста, предложите решить эту проблему
Спасибо