我在Twitter上的帖子中使用了belove代码
public class TwitterSocialHelper extends SocialHelper {
private static final String TAG = TwitterSocialHelper.class.getSimpleName();
private static final String CONSUMER_KEY = "AZZZZZ";
private static final String CONSUMER_SECRET = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
private static final String CALLBACK_URL = "oauth://abc";
private static final String IEXTRA_OAUTH_VERIFIER = "oauth_verifier";
private static final int AUTH_REQUEST_CODE = 1234;
private final Twitter twitter;
private RequestToken requestToken;
public TwitterSocialHelper(Activity activity, Listener listener) {
super(TYPE_TWITTER, activity, listener);
if (android.os.Build.VERSION.SDK_INT > 15) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(CONSUMER_KEY);
configurationBuilder.setOAuthConsumerSecret(CONSUMER_SECRET);
Configuration configuration = configurationBuilder.build();
TwitterFactory tf = new TwitterFactory(configuration);
twitter = tf.getInstance();
if (isConnected()) {
twitter.setOAuthAccessToken(new AccessToken(PreferencesManager.getTwitterToken(activity), PreferencesManager.getTwitterSecret(activity)));
}
}
private boolean isConnected() {
return !TextUtils.isEmpty(PreferencesManager.getTwitterToken(activity))
&& !TextUtils.isEmpty(PreferencesManager.getTwitterSecret(activity));
}
private void connect() {
try {
requestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
// TwitterAuthActivity.start(activity, requestToken.getAuthenticationURL(), AUTH_REQUEST_CODE);
} catch (TwitterException e) {
LogUtils.info(TAG + " " + e.getErrorMessage());
LogUtils.info(TAG + " " + e.getExceptionCode());
e.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == AUTH_REQUEST_CODE) {
String url = TwitterAuthActivity.getResultUrl(data);
if (url != null && url.startsWith(CALLBACK_URL)) {
Uri uri = Uri.parse(url);
String verifier = uri.getQueryParameter(IEXTRA_OAUTH_VERIFIER);
try {
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
PreferencesManager.setTwitterToken(activity, accessToken.getToken());
PreferencesManager.setTwitterSecret(activity, accessToken.getTokenSecret());
} catch (Exception e) {
Log.e(TAG, "Exception while parsing tokens", e);
listener.onExceptionOccured(e);
}
}
}
}
}
等级
implementation group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.6'
for
以前运行正常,但是突然显示如下错误消息。,对于requestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
来说,我看到过很多关于同一错误消息的帖子,主要用户建议在解决方案下方对我不起作用。
1)将twitter4j从4.0.3更新为最新的4.0.6 =不适用于我
2):添加回调URL =我已经添加了回调URL。
403:请求已被理解,但已被拒绝。一个 随附的错误消息将说明原因。此代码用于 由于更新限制,请求被拒绝 (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following)。 不允许将此客户端应用程序使用的回调URL。 可以在您的应用程序中调整批准的回调URL 设定 有关讨论可以在Internet上找到: http://www.google.co.jp/search?q=8e063946或 http://www.google.co.jp/search?q=fe607b42 TwitterException {exceptionCode = [8e063946-fe607b42],statusCode = 403,message = null,code = -1,retryAfter = -1, rateLimitStatus = null,版本= 4.0.6} 在twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164) 在twitter4j.HttpClientBase.request(HttpClientBase.java:57) 在twitter4j.HttpClientBase.post(HttpClientBase.java:86) 在twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:115) 在twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:92) 在twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:296) 在android_support.ane.b(TwitterSocialHelper.java:69) 在android_support.ane.a(TwitterSocialHelper.java:102)
任何人都可以帮助解决此问题吗?