1
我想开发一个使用LinkedIn API的Android应用程序(冰淇淋三明治)。为此,我使用Scribe库来实现OAuth进程。OAuth 1.0与Android 4.x和scribe
我的问题是,我不知道如何让用户允许我的LinkedIn应用程序访问他的LinkedIn数据后,从Web视图获取访问令牌。
在网络上,我发现了很多教程,但没有教程解释如何获得与冰淇淋sandwhich令牌。我在网上看到的是,我不能在UI线程中用冰淇淋三明治创建http调用。因此我开发了一个异步任务来获得授权url。
在我的活动我有了以下OnClickListener一个按钮:
private OnClickListener createOnClickListener(final SocialAPI socialAPI) {
return new OnClickListener() {
@Override
public void onClick(View arg0) {
if(PreferencesManager.getToken(AccountsActivity.this, socialAPI) == null) {
new OAuthRequestTokenAsyncTask(AccountsActivity.this, new AsyncTaskResultHandler<String>() {
@Override
public void handleResult(String result) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(result)));
}
@Override
public void onError(Exception e) {
//nothing to do here
}
}).execute(socialAPI);
}
}
};
}
异步任务作如下:
protected String doInBackground(SocialAPI... socialAPIs) {
SocialAPI socialAPI = socialAPIs[0];
OAuthService oauthService = new ServiceBuilder()
.provider(socialAPI.apiClass)
.apiKey(socialAPI.consumerKey)
.apiSecret(socialAPI.consumerSecret)
.callback(socialAPI.callbackUrl)
.build();
Token requestToken = oauthService.getRequestToken();
return oauthService.getAuthorizationUrl(requestToken);
}
用户输入的Web视图他的证件后,原始活动再次由回调操作noNewIntent调用:
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
final Uri uri = intent.getData();
System.out.println("what to do here");
}
在这个位置我不知道如何获得访问令牌。我想我必须开发,我有注入请求令牌第二异步任务(根据隶文档),但如何从操作做到这一点onNewIntent ...
Verifier verifier = new Verifier("verifier");
Token accessToken = service.getAccessToken(requestToken, verifier);
顺便说一句,如果应用程序执行在HTTP调用在UI线程,然后我得到以下异常:
org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
在此先感谢...
听起来像你缺少互联网许可? –
TomTasche
2013-04-27 16:28:29
我已经在清单文件中设置了权限...... – LaMinifaldaWue 2013-04-28 00:51:50