[英]why am i getting an error on .verifyCredentials()
I want to get the data using twitter's fabric api but whenever i tend to verify credentials and use a callback it shows an error , specifically ,"The arguments differ in length" 我想使用twitter的fabric API获取数据,但是每当我倾向于验证凭据并使用回调时,它都会显示错误,特别是“参数长度不同”
void getUserData() {
Twitter.getApiClient(session).getAccountService()
.verifyCredentials(true, false, new Callback<User>() {
@Override
public void failure(TwitterException e) {
}
@Override
public void success(Result<User> userResult) {
User user = userResult.data;
String twitterImage = user.profileImageUrl;
try {
Log.d("imageurl", user.profileImageUrl);
Log.d("name", user.name);
Log.d("email",user.email);
Log.d("des", user.description);
Log.d("followers ", String.valueOf(user.followersCount));
Log.d("createdAt", user.createdAt);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Just change the twitter dependency in your Build.Gradle from 只需更改Build.Gradle中的twitter依赖项即可
compile('com.twitter.sdk.android:twitter:2.0.0@aar') {
transitive = true;
}
to 至
compile('com.twitter.sdk.android:twitter:1.11.0@aar') {
transitive = true;
}
The new version of the .verifyCredentials() method doesn't accept a callback hence your error. .verifyCredentials()方法的新版本不接受回调,因此会导致您的错误。
If you check the fabric documentation, it shows two version of the method, however when I tried to open the source code in Android Studio but it had only the version without the callback. 如果查看结构文档,它会显示该方法的两个版本,但是当我尝试在Android Studio中打开源代码时,却只有该版本而没有回调。
You can solve the isssue as follows: 您可以按以下步骤解决问题:
//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;
String twitterImage = user.profileImageUrl;
try {
Log.d("imageurl", user.profileImageUrl);
Log.d("name", user.name);
Log.d("email",user.email);
Log.d("des", user.description);
Log.d("followers ", String.valueOf(user.followersCount));
Log.d("createdAt", user.createdAt);
} catch (Exception e) {
e.printStackTrace();
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.