Problem In Callback In Twitter In Android
Solution 1:
The problem is that Callback URl. We should give one Dummy Callback URL in the Field Name of CallBack URL in Application' s Settings Page.
If we do like that and send the Call Back URL in our code, after successful Login there will be a option called Redirecting to your Application
For Further Reference check this Link for Twitter
Solution 2:
Have you found where the problem come from? I had the same one exeception and finally I found where this come from. That right that the setting page of Twitter had change and you can't no more selecting Web Based application or Desktop Application. But here is the tips: in settings of your Twitter application just fill the Callback URL with a dummy one like http://www.dummy.com . This will implicitly set your application has a web browser and then when you send your own callback it will remplace the dummy one. I had spend a lot of times to find this so I hope this answer will help someone.
Solution 3:
Adding the below Callback URL
in to app would solve the problem. It will redirect user to the Application
which start it to authenticate user's Twitter
account_
update in Manifest
_
<activityandroid:name="<YOUR ACTIVITY NAME>"android:launchMode="singleTask"android:theme="@android:style/Theme.Translucent.NoTitleBar"android:screenOrientation="portrait"><intent-filter><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter><intent-filter><actionandroid:name="android.intent.action.VIEW" /><categoryandroid:name="android.intent.category.DEFAULT" /><categoryandroid:name="android.intent.category.BROWSABLE" /><dataandroid:scheme="x-oauthflow-twitter"android:host="callback" /></intent-filter>
In Your TwitterManager
where you have all your TwitterFactory
and the required things_
finalpublicstaticStringCALLBACK_SCHEME="x-oauthflow-twitter";
finalpublicstaticStringCALLBACK_URL= CALLBACK_SCHEME + "://callback";
publicstaticfinalStringTWITTER_IEXTRA_OAUTH_VERIFIER="oauth_verifier";
Finally you can get everything that you need_
e.g., getHost
, getScheme
, getEncodedQuery
, getQuery
, getEncodedSchemeSpecificPart
and more as per your need using the intent
that return by the call back_
@OverrideprotectedvoidonNewIntent(final Intent intent) {
super.onNewIntent(intent);
newAsyncTask<Void,Void,Void>(){
@Overrideprotected Void doInBackground(Void... arg0) {
Uriuri= intent.getData();
if (uri != null && uri.toString().startsWith(TwitterManager.TWITTER_CALLBACK_URL)) {
Stringverifier= uri.getQueryParameter(TwitterManager.TWITTER_IEXTRA_OAUTH_VERIFIER);
Log.e("---ActivityMain-onNewIntent---", "verifier:"+verifier+", uri- getQuery:"+uri.getQuery());
Log.i(ApplicationPockets.TAG, "verifier : "+verifier);
if(verifier != null){
try {
/*
*---Get the AccessToken and do what you like ... :)
*/AccessTokenaccessToken= twitter.getOAuthAccessToken(requestToken, verifier);
SharedPreferences.Editore= context.getSharedPreferences(SF_TWITTER, Context.MODE_PRIVATE).edit();
e.putString(TWITTER_PREF_KEY_TOKEN, accessToken.getToken());
e.putString(TWITTER_PREF_KEY_SECRET, accessToken.getTokenSecret());
e.commit();
//Extra you would like to do...
} catch (TwitterException e) {
e.printStackTrace();
}
}else{
//Logout Twitter.
}
}
returnnull;
}
}.execute();
}
Your RequestToken_
try {
RequestTokenrequestToken= twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
//Toast.makeText(activity, "Please authorize this app!", Toast.LENGTH_LONG).show();
activity.startActivity(newIntent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
} catch (TwitterException e) {
e.printStackTrace();
}
I hope this will help everyone_
Post a Comment for "Problem In Callback In Twitter In Android"