回调网址没有返回到Android屏幕

时间:2013-11-30 06:51:39

标签: android

Linkedin授权回调网址没有返回到Android屏幕。以下是我尝试过的代码:

String linkedinKey = "xxxxx";    //add your LinkedIn key
    String linkedinSecret = "xxxx"; //add your LinkedIn Secret

    public static final String OAUTH_CALLBACK_SCHEME = "callback";
    public static final String OAUTH_CALLBACK_URL = "x-oauthflow-linkedin" + ":///"+ "callback";

    LinkedInRequestToken LinkedinrequestToken ;
    Intent i;
    final LinkedInOAuthService oauthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(linkedinKey,linkedinSecret); 
    final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(linkedinKey,linkedinSecret);   
     LinkedInApiClient client;

 ImageView btnLinkedInLogin=(ImageView)findViewById(R.id.btnLinkedInLogin);
            btnLinkedInLogin.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    LinkedinrequestToken = oauthService.getOAuthRequestToken(OAUTH_CALLBACK_URL);
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(LinkedinrequestToken.getAuthorizationUrl()));
                  //  i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(i);


                }
            });

private void OnNewIntent()
    {
        Log.d("newintent","hi");
        String verifier = i.getData().getQueryParameter("oauth_verifier");

        LinkedInAccessToken accessToken = oauthService.getOAuthAccessToken(LinkedinrequestToken, verifier);
        Log.d("token",accessToken.toString());
    }

的Manifest.xml

   <activity
            android:name=".Login"
            android:launchMode="singleTop"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/AppThemes" >
            <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>
                <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:scheme="x-oauth-linkedin" android:host="callback" />

            </intent-filter>
        </activity>

但我的网页在授权成功时停止。它不会返回到Android屏幕。 我的OnNewIntent()函数未被调用。

1 个答案:

答案 0 :(得分:1)

正如我所看到的,你以错误的方式使用了onNewIntent,只需使用这样:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.d("newintent","hi");
        String verifier = i.getData().getQueryParameter("oauth_verifier");

        LinkedInAccessToken accessToken = oauthService.getOAuthAccessToken(LinkedinrequestToken, verifier);
        Log.d("token",accessToken.toString());
}

您可以通过将onNewIntent放入onCreate方法,如下所示来调用onNewIntent,所以请确保您是否这样做:

@Override
public void onCreate(Bundle savedState)
{
    super.onCreate(savedState);
    onNewIntent(getIntent());
}

希望这会有所帮助。谢谢。 :)