Android开发人员-回调URL不工作。。。(0_o)
我正在为我的研究开发一个android应用程序,我正在与OAuth(路标库)合作,从web服务访问用户数据,这也是开发过程的一部分。我可以通过OAuth的常见步骤,使用Uri(用于回调应用程序),并可以进入调用设备浏览器的步骤,选择验证我的应用程序,下一步应该将浏览器重定向回应用程序 相反,我得到了一个类似“您没有打开的权限: 应用程序chema://appName?authorizationSensitiveInfo..." “?”后面的附件是 来自的oauth_令牌和oauth_验证器 服务(我们可以承担所有步骤 直到重定向完成为止 “正确”) 可能的问题存在于Android开发人员-回调URL不工作。。。(0_o),android,oauth,callback,android-manifest,signpost,Android,Oauth,Callback,Android Manifest,Signpost,我正在为我的研究开发一个android应用程序,我正在与OAuth(路标库)合作,从web服务访问用户数据,这也是开发过程的一部分。我可以通过OAuth的常见步骤,使用Uri(用于回调应用程序),并可以进入调用设备浏览器的步骤,选择验证我的应用程序,下一步应该将浏览器重定向回应用程序 相反,我得到了一个类似“您没有打开的权限: 应用程序chema://appName?authorizationSensitiveInfo..." “?”后面的附件是 来自的oauth_令牌和oauth_验证器 服务
应用程序中chema://appName
零件。据我所知,这是重定向URL,它告诉Uri使用手机浏览器定位我的应用程序并调用onResume()方法。应用程序的值在哪里chema://appName
来自(在清单中定义?如果是,在哪里定义?)
为什么许可有问题?我必须为我的Uri设置访问我的应用程序的权限吗?我迷路了…如果你需要代码片段来帮助我,请回复,我没有包含任何代码,因为这更像是我刚刚错过的一个概念…我现在不在我的机器上,但我可以提供代码,如果这能让事情更容易理解的话。在这里真的让我头疼
作为对一个好答案的回应,这里是我如何处理我的简历
protected void onResume() {
super.onResume();
Uri uri = this.getIntent().getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
Log.d("StepGreenM", uri.toString());
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
Log.d("StepGreenM", verifier);
try {
provider.retrieveAccessToken(consumer, verifier);
TOKEN = consumer.getToken();
REQUEST_SECRET = consumer.getTokenSecret();
Log.d("StepGreenM", TOKEN);
Log.d("StepGreenM", REQUEST_SECRET);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
uri = getIntent().getData();
if (uri != null && CALLBACK_URI.getScheme().equals(uri.getScheme())) {
String token = settings.getString(HomeScreen.REQUEST_TOKEN, null);
String secret = settings.getString(HomeScreen.REQUEST_SECRET, null);
Intent i = new Intent(Intent.ACTION_VIEW); // Intent to go to the action view
try {
if(!(token == null || secret == null)) {
consumer.setTokenWithSecret(token, secret);
}
String otoken = uri.getQueryParameter(OAuth.OAUTH_TOKEN);
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
// We send out and save the request token, but the secret is not the same as the verifier
// Apparently, the verifier is decoded to get the secret, which is then compared - crafty
// This is a sanity check which should never fail - hence the assertion
Assert.assertEquals(otoken, consumer.getToken());
// This is the moment of truth - we could throw here
provider.retrieveAccessToken(consumer, verifier);
// Now we can retrieve the goodies
token = consumer.getToken();
secret = consumer.getTokenSecret();
//Save it to a settings file
HomeScreen.saveAuthInformation(settings, token, secret);
// Clear the request stuff, now that we have the real thing
HomeScreen.saveRequestInformation(settings, null, null);
i.putExtra(USER_TOKEN, token);
i.putExtra(CONSUMER_SECRET, secret);
//GO TO APPLICATION
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
} finally {
startActivity(i); // we either authenticated and have the extras or not, but are going to the action view
this.setContentView(R.layout.indivaction);
finish();
}
}
}
不确定是什么导致了这个崩溃…但就像我说的,当调用这个方法时,它会强制关闭。我知道它通过了重定向,因为我使用httpSniffer来检查往返于服务器的消息…为了使回调uri正常工作,您需要在要在其中使用它的活动的清单中添加类似于以下内容的意图过滤器
<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="appSchema" android:host="appName"/>
</intent-filter>
如果不使用singleTask或singleInstance,您可以
@Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Uri uri = intent.getData();
String oauthToken = uri.getQueryParameter("oauth_token");
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
//...do what you need with the parameters
}
我相信这应该行得通
此外,如果我没有弄错的话,您提供的回调url应该包括?、so“appSchema://appName?“我会尝试一下,并让您知道这是否有效。我在我的主要活动中使用了manifest intent过滤器jazz,我将把它移动到使用Oauth的活动中,并将“?”附加到我的回调URL中。非常感谢。您是否通过类型为ACTION\u的意向视图启动浏览器?您可能会遇到的一个麻烦是,尽管浏览器会重定向回您的应用程序,但它不会自动关闭自己。不确定这是否会阻碍您尝试完成的任务。我正在使用ACTION_VIEW,我的一个问题是如何确定我是否使用singleinstance/singleTop,它是否简单到如果我看不到这些单词(我肯定也不会手动调用),那么我可以使用onResume而不是onNewIntent()。我在清单中的活动中包含了意图过滤器,但现在我的应用程序强制关闭。我试图在恢复时将oauth信息从回调保存到SharedReferences文件,以便我的应用程序的其他活动可以使用该文件。但不是权限消息,而是强制关闭:(啊,我的错,我指的是singleInstance/singleTask,但是如果您没有在清单中为该活动设置android:launchMode,它应该使用standard,这意味着您正确地使用onResume而不是OnWintent。当您使用完浏览器后,回调是否会重新调用您的活动?是否必须使用super.onResume()和super.onNewIntent()分别在那些狙击手中?
@Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Uri uri = intent.getData();
String oauthToken = uri.getQueryParameter("oauth_token");
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
//...do what you need with the parameters
}