我在Twitter集成应用程序中使用以下代码。
Twitter.getApiClient(session).getAccountService()
.verifyCredentials(true, false, new Callback<User>() {
@Override
public void failure(TwitterException e) {
//If any error occurs handle it here
}
@Override
public void success(Result<User> userResult) {
// get the user details
}
});
抛出以下错误。
error: method verifyCredentials in interface AccountService cannot be applied to given types;
required: Boolean,Boolean
found: boolean,boolean,<anonymous Callback>
reason: actual and formal argument lists differ in length
有人可以帮我解决这个错误吗?
答案 0 :(得分:4)
虽然文档仍然为该方法指定了两个版本 VerifyCredentials(),一个将回调作为参数而一个不回调的,仍然遇到了同样的问题。
我尝试在Android Studio中打开源代码,但它只有没有回调的版本。
以下是我解决问题的方法。
//Getting the account service of the user logged in
Call<User> call = Twitter.getApiClient(session).getAccountService()
.verifyCredentials(true, false);
call.enqueue(new Callback<User>() {
@Override
public void failure(TwitterException e) {
//If any error occurs handle it here
}
@Override
public void success(Result<User> userResult) {
//If it succeeds creating a User object from userResult.data
User user = userResult.data;
setProfilePic(user.profileImageUrl.replace("_normal", ""));
twitterLoginButton.setVisibility(View.GONE);
}
});
以下是文档的链接:Fabric Documentation
答案 1 :(得分:0)
在按钮上单击Listener的成功方法,调用此方法:
TwitterSession session;
@Override
public void success(Result<TwitterSession> twitterSessionResult) {
session = twitterSessionResult.data;
getUserData(session);
Toast.makeText(LoginActivity.this, "success", Toast.LENGTH_SHORT).show();
}
void getUserData(TwitterSession session) {
Call<User> call = Twitter.getApiClient(session).getAccountService().verifyCredentials(true, false);
call.enqueue(new Callback<User>() {
@Override
public void failure(TwitterException e) {
}
@Override
public void success(Result<User> userResult) {
User user = userResult.data;
userID = String.valueOf(user.id);
}
});
}