'com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 403
I have recently added fabric plugin in my android studio, but i am not finding twitter login option on that plugin. When i search on google then i found one question that fabric has recently removed twitter login kit . so i integrate twitterkit using twitter official documentation. I integrate twitterkit and implement code according to twitter developer site, but i am facing issue.
This is the Error log:
E/Twitter: Failed to get app auth token
com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 403
at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6209)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Authorize failed.
at com.twitter.sdk.android.core.identity.AuthHandler.handleOnActivityResult(AuthHandler.java:98)
at com.twitter.sdk.android.core.identity.TwitterAuthClient.onActivityResult(TwitterAuthClient.java:161)
at com.twitter.sdk.android.core.identity.TwitterLoginButton.onActivityResult(TwitterLoginButton.java:131)
at in.crazyfingers.cyny.social_login.ActivitySocialSignIn.onActivityResult(ActivitySocialSignIn.java:305)
at android.app.Activity.dispatchActivityResult(Activity.java:7007)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4173)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4220)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1559)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6209)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
I have checked Question 1 and Question 2 and other so many question which is related to this issue but its not worked for me. Help would be appreciate. Thanks in advance.
This is my app level build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.twitter"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
// Include all the Twitter APIs
compile 'com.twitter.sdk.android:twitter:3.0.0'
}
This is my CustomApplication.Java file.
public class CustomApplication extends Application
{
public void onCreate() {
Twitter.initialize(this);
}
}
This is my TwitterLogin.java file
public class TwitterLogin extends AppCompatActivity
{
public static final String TAG = "[TwitterLogin]";
private String TWITTER_KEY = "here my app twitter key";
private String TWITTER_SECRET = "here my app secret key";
private TwitterLoginButton loginButton;
private TextView status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twitter_login);
TwitterConfig config = new TwitterConfig.Builder(this)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET))
.debug(true)
.build();
Twitter.initialize(config);
loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
loginButton.setCallback(new LoginHandler());
}
private class LoginHandler extends Callback<TwitterSession> {
@Override
public void success(Result<TwitterSession> twitterSessionResult) {
String output = "Status: " +
"Your login was successful " +
twitterSessionResult.data.getUserName() +
"nAuth Token Received: " +
twitterSessionResult.data.getAuthToken().token;
Log.e(TAG, "twitterSessionResult : " + output);
}
@Override
public void failure(TwitterException e) {
status.setText("Status: Login Failed");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Pass the activity result to the login button.
loginButton.onActivityResult(requestCode, resultCode, data);
}
}
Solution 1:[1]
I have searched in one whole day and i found the below solution. I don't know but it is worked fine for me.
I comment this line from the Application.java file.
//Twitter.initialize(this);
I have initialize Twitter
SDK as below and it will work for me.
//Initialize twitter SDK
TwitterConfig config = new TwitterConfig.Builder(this)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET))
.debug(true)
.build();
Twitter.initialize(config);
Set callback
on twitter button as below.
loginButton.setCallback(new TwitterLogin.LoginHandler());
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ninja |