gpt4 book ai didi

java - com.twitter.sdk.android.core.TwitterApiException : HTTP request failed, 状态:403

转载 作者:行者123 更新时间:2023-11-29 14:26:29 25 4
gpt4 key购买 nike

我最近在我的 android 工作室中添加了 fabric 插件,但我没有在该插件上找到 Twitter 登录选项。当我在谷歌上搜索时,我找到了一个 question该结构最近删除了 Twitter 登录工具包。所以我使用 twitter official documentation 整合了 twitterkit .我根据twitter developer site集成twitterkit并实现代码,但我遇到了问题。

这是错误日志:

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)

我检查了Question 1Question 2以及其他许多与此问题相关但对我不起作用的问题。帮助将不胜感激。提前致谢。

这是我的应用级build.gradle文件

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'

}

这是我的CustomApplication.Java 文件。

public class CustomApplication extends Application
{
public void onCreate() {
Twitter.initialize(this);
}
}

这是我的 TwitterLogin.java 文件

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);
}
}

最佳答案

我搜索了一整天,找到了以下解决方案。我不知道,但对我来说效果很好。

我从 Application.java 文件中注释了这一行。

//Twitter.initialize(this);

我已经初始化了 Twitter SDK,如下所示,它对我有用。

//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);

在推特按钮上设置回调如下。

loginButton.setCallback(new TwitterLogin.LoginHandler());

关于java - com.twitter.sdk.android.core.TwitterApiException : HTTP request failed, 状态:403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44523590/

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