0

こんにちは、Twitter で auto を使用しています。

アクセスを「読み取り専用」から「読み取りと書き込み」に変更するまで、私のコードはうまく機能していました。

私の問題は、Web ページで [サインイン] をクリックした後、アプリに戻らないことです。

私はそれについて読みましたが、それがコールバック URL に関するものであることを知っています。

これが私のコードです:

static final String TWITTER_CALLBACK_URL = "oauth://t4jsample";


private void loginToTwitter() 
        {
            // Check if already logged in

                ConfigurationBuilder builder = new ConfigurationBuilder();
                builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
                builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
                Configuration configuration = builder.build();

                TwitterFactory factory = new TwitterFactory(configuration);
                twitter = factory.getInstance();

                try {
                    requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);

                    this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));

                } catch (TwitterException e) {

                    Toast.makeText(OpeningPage.this, "Something went wrong, please try again", Toast.LENGTH_SHORT).show();

                    e.printStackTrace();
                }
}

私のマニフェスト:

    <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:host="t4jsample"
            android:scheme="oauth" />
    </intent-filter>

私のツイッター設定ページ:

ここに画像の説明を入力

助けてくれてありがとう

4

1 に答える 1

0

あなたの場合、外部ブラウザアプリではなく、アプリケーションに表示する必要があります。次のようなカスタム Web クライアントを作成した後、Android で WebView を使用します。

private class CustomWebClient extends WebViewClient {
...

 @Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {

 } 

}

そしてあなたのWebViewに設定してください:

webView.setWebViewClient(new CustomWebClient());

メソッドでshouldOverrideUrlLoadingは、コールバック URL を追跡する必要があります。

于 2013-10-16T10:23:10.627 に答える