我需要你的帮助才能找出回调网址不能与我合作的原因,因为我无法回到活动中的onResume
这是我使用的代码
public class OAuthTrialsActivity extends Activity {
/** Called when the activity is first created. */
private static final String CONSUMER_KEY = "66aba0d1168566c364d86e6087bea04e04e9ff754";
private static final String CONSUMER_SECRET = "aec138c913cb21763b4983de77683a04";
private static final int CALL_BACK = 1;
private static String ACCESS_KEY = null;
private static String ACCESS_SECRET = null;
private static final String REQUEST_URL = "http://yakhabar.tawasoldev.com/index.php/api/requestToken";
private static final String ACCESS_TOKEN_URL = "http://yakhabar.tawasoldev.com//index.php/api/accessToken";
private static final String AUTH_URL = "http://yakhabar.tawasoldev.com/index.php/api/AuthorizeApp";
private static final String CALLBACK_URL = "http://localhost/app.php?third=true";
private static CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
CONSUMER_KEY, CONSUMER_SECRET);
private static CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
REQUEST_URL, ACCESS_TOKEN_URL, AUTH_URL);
Button btnLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
provider.setOAuth10a(true);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String authURL = provider.retrieveRequestToken(
consumer, CALLBACK_URL);
Log.d("OAuthTwitter authURL", authURL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse(authURL)));
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
});
}
@Override
public void onResume() {
super.onResume();
Uri uri = this.getIntent().getData();
Log.d("ana shoftha","ahmed"+uri);
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
Log.d("ana shoftha","ahmed");
Log.d("OAuthTwitter uri", uri.toString());
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
Log.d("OAuthTwitter verifier", verifier);
try {
provider.retrieveAccessToken(consumer, verifier);
ACCESS_KEY = consumer.getToken();
ACCESS_SECRET = consumer.getTokenSecret();
Log.d("OAuthTwitter key ", ACCESS_KEY);
Log.d("OAuthTwitter secret", ACCESS_SECRET);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
}
}
这是清单
<activity android:name=".OAuthTrialsActivity" android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="localhost" />
</intent-filter>
</activity>
该服务将我引导至带有验证者的回调网址但我可以提取它,因为我没有回到活动
任何人都可以帮助并给我一个解决方案
答案 0 :(得分:0)
我今天遇到了同样的问题。在Twitter上,我没有在设置页面上指定回调URL。我添加后,我的onReceive开始工作了。网址可以是任何内容,不是特定于您的应用程序。希望这可以帮助!