Android Dev - 回调网址无效… (0_o)
我正在为我的研究开发一个Android应用程序,我正在使用OAuth(路标库)来访问来自Web服务的用户数据,这也是开发过程的一部分。我能够完成OAuth的常用步骤,并使用Uri(用于回调应用程序),并且可以进入我调用设备浏览器的步骤,选择验证我的应用程序,下一步是支持将浏览器重定向到应用程序....
相反,我得到一个错误,上面写着“你没有权限打开:
appSchema:// APPNAME authorizationSensitiveInfo ......”
'?'之后的附属物是的
oauth_token和oauth_verifier来自
服务(我们可以承担所有步骤
直到重定向
“正确”)。
可能存在的问题在
appSchema://appName
部分内。根据我的理解,这是重定向URL,告诉Uri使用手机的浏览器来定位我的应用程序并调用onResume()方法。 appSchema://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();
}
}
}
不确定是什么让它崩溃了......但就像我说的那样,当调用这个方法时,force会关闭。我知道它通过了重定向,因为我使用httpSniffer来检查进出服务器的消息......
没有找到相关结果
已邀请:
1 个回复
碧肮械淌设
现在,如果您的活动使用的是singleInstance / singleTask,则应使用类似于以下内容的内容:
如果不使用singleTask或singleInstance,你可以这样做
我相信这应该有效。 另外,如果我没有弄错,你提供的回调网址应该包含?,那么“appSchema:// appName?”