2012-07-22 79 views
5

我試圖將LinkedIn與Android集成。在eclipse中的LinkedIn身份驗證問題

LinkedinDialog.liToken = LinkedinDialog.oAuthService.getOAuthRequestToken(OAUTH_CALLBACK_URL); 




07-22 17:32:08.026: E/AndroidRuntime(26733): FATAL EXCEPTION: main 
07-22 17:32:08.026: E/AndroidRuntime(26733): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.devicebee.app.transportfinder/com.devicebee.app.transportfinder.LinkedInActivity}: com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: https://api.linkedin.com/uas/oauth/requestToken 

使用教程我已經應用下面的代碼...

private void setWebView() 
    { 
     LinkedinDialog.oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(LINKEDIN_CONSUMER_KEY, LINKEDIN_CONSUMER_SECRET); 
     LinkedinDialog.factory = LinkedInApiClientFactory.newInstance(LINKEDIN_CONSUMER_KEY, LINKEDIN_CONSUMER_SECRET); 

     LinkedinDialog.liToken = LinkedinDialog.oAuthService.getOAuthRequestToken(OAUTH_CALLBACK_URL); 

     WebView mWebView = (WebView) findViewById(R.id.webkitWebView1); 
     mWebView.getSettings().setJavaScriptEnabled(true); 

     Log.i("LinkedinSample", LinkedinDialog.liToken.getAuthorizationUrl()); 
     mWebView.loadUrl(LinkedinDialog.liToken.getAuthorizationUrl()); 
     mWebView.setWebViewClient(new HelloWebViewClient()); 

     mWebView.setPictureListener(new PictureListener() 
     { 
      public void onNewPicture(WebView view, Picture picture) 
      { 
       if(progressDialog != null && progressDialog.isShowing()) 
       { 
        progressDialog.dismiss(); 
       } 

      } 
     }); 

    } 

我得到下面的錯誤我已經搜索互聯網,並根據一些帖子那是因爲我在一些代理。但我很確定我沒有任何代理人。如果有人能告訴我該怎麼做,請。 最好的問候

回答

0

確定這是我用什麼,現在工作得很好

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.widget.Toast; 

import com.google.code.linkedinapi.client.LinkedInApiClient; 
import com.google.code.linkedinapi.client.LinkedInApiClientFactory; 
import com.google.code.linkedinapi.client.oauth.LinkedInAccessToken; 
import com.google.code.linkedinapi.client.oauth.LinkedInOAuthService; 
import com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceFactory; 
import com.google.code.linkedinapi.client.oauth.LinkedInRequestToken; 

public class LITestActivity extends Activity { 


    public static final String CONSUMER_KEY = "xx"; 
    public static final String CONSUMER_SECRET = "xx"; 
    private final static String APP_PNAME = "xx"; 


    public static final String APP_NAME = "xx; 
    public static final String OAUTH_CALLBACK_SCHEME = "xx"; 
    public static final String OAUTH_CALLBACK_HOST = "xxx"; 
    public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME 
      + "://" + OAUTH_CALLBACK_HOST; 

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

// TextView tv = null; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    // setContentView(R.layout.main); 
    // tv = (TextView) findViewById(R.id.tv); 
     try 
     { 
     liToken = oAuthService.getOAuthRequestToken(OAUTH_CALLBACK_URL); 
     Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken 
       .getAuthorizationUrl())); 
     startActivity(i); 
     }catch (Exception e) { 
      Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_SHORT).show(); 

     } 
    } 

    @Override 
    protected void onNewIntent(Intent intent) { 
     String verifier = intent.getData().getQueryParameter("oauth_verifier"); 
     try{ 
     LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(
       liToken, verifier); 
     client = factory.createLinkedInApiClient(accessToken); 
     String tweet = "Download Android App " + "market://details?id=" + APP_PNAME; 
     client.postNetworkUpdate(tweet); 
     //Person p = client.getProfileForCurrentUser(); 
     //tv.setText(p.getLastName() + ", " + p.getFirstName()); 
    //  p.setCurrentStatus("tweet"); 

     }catch (Exception e) { 
      Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_SHORT).show(); 
     } 
     finish(); 

    } 
} 

圖書館是

linkedin-j-android.jar 
signpost-jetty6-1.2.1.1.jar 
signpost-core-1.2.1.1.jar 
+0

偉大的!我正在使用完全相同的代碼,但我一直得到「訪問發佈拒絕的股份」任何想法可能會導致什麼?我試圖添加權限使用範圍,但它只是被忽略 – 2012-08-29 23:52:58

+0

請閱讀此http://developer.linkedin.com/documents/authentication#granting – 2013-01-17 14:47:37

+0

嗨,我的應用程序工作正常與LinkedIn,但我收到此設備上的錯誤與冰淇淋三明治**與服務提供商溝通失敗:null **。任何人都可以請幫我嗎? – 2013-03-20 09:12:45

1

很可能你正試圖在你的UI線程上運行這個網絡不允許的地方。您需要在AsyncTask中實現oauth調用。

在UI線程上的網絡調用被允許,直到Android 3.0。您所遵循的教程可能是在變化發生之前編寫的。

- EDIT-- 要測試這是否屬實,您可以嘗試將應用程序目標設置爲API 10並查看問題是否消失。