我使用Twitter sdk这个Android应用程序 . 可以按下twitter按钮,但在尝试连接到Twitter后,我得到一个简短的Toast“无法完成动作”
我的代码:
public class MainActivity extends AppCompatActivity {
TwitterLoginButton loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Twitter.initialize(this);
setContentView(R.layout.activity_main);
TwitterConfig config = new TwitterConfig.Builder(this)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig(getString(R.string.tw__login_btn_txt), getString(R.string.tw__max_tweet_chars)))
.debug(true)
.build();
Twitter.initialize(config);
loginButton = (TwitterLoginButton) findViewById(R.id.login_button);
loginButton.setCallback(new Callback() {
@Override
public void success(Result result) {
// Do something with result, which provides a TwitterSession for making API calls
Toast.makeText(MainActivity.this, "hi", Toast.LENGTH_SHORT).show();
}
@Override
public void failure(TwitterException exception) {
// Do something on failure
}
});
}
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);
}
}
和错误:
授权已完成,但出现错误
com.twitter.sdk.android.core.TwitterAuthException:授权失败 . 在com.twitter.sdk.android.core.identity.AuthHandler.handleOnActivityResult(AuthHandler.java:98)在com.twitter.sdk.android.core.identity.TwitterAuthClient.onActivityResult(TwitterAuthClient.java:171)在com.twitter .sdk.android.core.identity.TwitterLoginButton.onActivityResult(TwitterLoginButton.java:130)在com.twitter.ratz.william.test.MainActivity.onActivityResult(MainActivity.java:64)在android.app.Activity.dispatchActivityResult(活动的.java:7022)在android.app.ActivityThread.deliverResults(ActivityThread.java:4253)在android.app.ActivityThread.handleSendResult(ActivityThread.java:4300)在android.app.ActivityThread.-wrap20(ActivityThread.java)在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1588)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper.loop(Looper.java:154)在android.app .ActivityThread.main(ActivityThread.java:6321)位于com.android.internal.os.ZygoteInit上的java.lang.reflect.Method.invoke(Native Method)$ MethodAndArgsCalle r.run(ZygoteInit.java:886)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
android开发实例之minitwitter登录界面 代码 Android Twitter登录按钮无法正常工作“无法完成操作”...
如果觉得《android开发实例之minitwitter登录界面 代码 Android Twitter登录按钮无法正常工作》对你有帮助,请点赞、收藏,并留下你的观点哦!