Android:LinkedIn OAuth回拨无效

Mar*_*tin 6 android oauth

OAuth在我的Android应用程序中使用LinkedIn .我已经有一个LinkedIn应用程序,消费者密钥和秘密,因此我可以成功请求.

一切都很好,直到回调.该网页不回电话,我的意思是onNewIntentonResume方法不调用.网页仅显示带参数的回调网址.我的意思是它看起来像:

callback_url://?oauth_token=324sdf&oath_verifier=as21dsf
Run Code Online (Sandbox Code Playgroud)

这是我的所有代码:

try {
    consumer = new CommonsHttpOAuthConsumer("ConsumerKey", "ConsumerSecret");
provider = new CommonsHttpOAuthProvider("https://api.linkedin.com/uas/oauth/requestToken", "https://api.linkedin.com/uas/oauth/accessToken", "https://api.linkedin.com/uas/oauth/authorize");
    final String url = provider.retrieveRequestToken(consumer, Constants.OAUTH_CALLBACK_URL);
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND);
    startActivity(intent);                          
} catch (Exception e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

活性已经被定义为singleInstanceManifest.

有什么不对或缺失?

Mar*_*tin 2

经过长时间的研究,我自己找到了答案。

我已经将我的基类更改为可以在此处linkedin-j查看。

然后设置这个常量如下:

    public static final String CONSUMER_KEY = "ConsumerKey";
    public static final String CONSUMER_SECRET = "ConsumerSecret";
    public static final String OAUTH_CALLBACK_SCHEME = "callback";
    public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + ":///";
Run Code Online (Sandbox Code Playgroud)

并像这样初始化:

LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
LinkedInRequestToken liToken;
LinkedInApiClient client;

liToken = oAuthService.getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl()));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)

这个回调很好,我已经在 OnNewIntent 处理过:

String verifier = intent.getData().getQueryParameter("oauth_verifier");

LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
client = factory.createLinkedInApiClient(accessToken);
client.postNetworkUpdate("Test");
Run Code Online (Sandbox Code Playgroud)

就这样。