6

OAuthAndroid アプリでLinkedIn を使用しています。LinkedIn アプリケーション、コンシューマ キー、およびシークレットは既にあるので、正常にリクエストできます。

コールバックまではすべて問題ありません。Web ページがコールバックしていない、onNewIntentつまり、onResumeメソッドがコールされていないということです。Web ページには、パラメーター付きのコールバック URL のみが表示されます。つまり、次のようになります。

callback_url://?oauth_token=324sdf&oath_verifier=as21dsf

ここに私のすべてのコードがあります:

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();
}

アクティビティは のように既に定義されsingleInstanceていManifestます。

何が間違っているか、または不足していますか?

4

1 に答える 1

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 + ":///";

そしてそのように初期化します:

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);

これはうまくコールバックし、私は OnNewIntent で処理しました:

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

LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
client = factory.createLinkedInApiClient(accessToken);
client.postNetworkUpdate("Test");

それで全部です。

于 2012-07-26T12:34:08.650 に答える