2012-04-17 146 views
1

我正在爲我的Android應用程序構建LinkedIn共享功能。我可以登錄LinkedIn,但之後模擬器顯示空白屏幕。我究竟做錯了什麼?LinkedIn集成到Android應用程序

下面是代碼,我consumer_keyconsumer_secret刪除:

import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.DefaultHttpClient; 

import oauth.signpost.OAuth; 
import oauth.signpost.OAuthConsumer; 
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer; 
import android.app.Activity; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.content.SharedPreferences.Editor; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.EditText; 
import android.widget.TextView; 
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; 
import com.google.code.linkedinapi.schema.Person; 
import com.ndot.sample.R; 
import com.ndot.sample.TestConnect; 


public class LinkedinActivity extends Activity { 

    public static final String CONSUMER_KEY = "xxxxxxxxxxxxx"; 
    public static final String CONSUMER_SECRET = "xxxxxxxxxx"; 
    public static final String APP_NAME = "LITest"; 
    public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin"; 
    public static final String OAUTH_CALLBACK_HOST = "litestcalback"; 
    public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME 
      + "://" + OAUTH_CALLBACK_HOST; 
    private static final int BOOK_SELECT = 1; 
    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    HttpPost post = new HttpPost("https://api.linkedin.com/v1/people/~/shares"); 

    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; 
    private String oauth_verifier; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.hionCreate(savedInstanceState); 
     setContentView(R.layout.post); 
     tv = (EditText) findViewById(R.id.postscreen); 
     liToken = oAuthService.getOAuthRequestToken(OAUTH_CALLBACK_URL); 
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken 
       .getAuthorizationUrl())); 
    Log.d("log",liToken.getAuthorizationUrl()); 


    } 

     @Override 
    protected void onNewIntent(Intent intent) { 
     String verifier = intent.getData().getQueryParameter("oauth_verifier"); 
     LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier); 
     client = factory.createLinkedInApiClient(accessToken); 
     client.postNetworkUpdate("LinkedIn Android app test"); 
     Person p = client.getProfileForCurrentUser(); 
     tv.setText(p.getLastName() + ", " + p.getFirstName()); 
     LinkedInAccessToken accessToken1 = oAuthService.getOAuthAccessToken(liToken, oauth_verifier); 
     SharedPreferences prefs = null; 
     final Editor edit = prefs.edit(); 
     edit.putString(OAuth.OAUTH_TOKEN, accessToken.getToken()); 
     edit.putString(OAuth.OAUTH_TOKEN_SECRET, accessToken.getTokenSecret()); 
     edit.putString("linkedin_login", "valid"); 


    } 
    protected void onNewIntent1(Intent intent) { 
    String verifier = intent.getData().getQueryParameter("oauth_verifier"); LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier); 
    client = factory.createLinkedInApiClient(accessToken); 

    Intent t = new Intent(LinkedinActivity.this, LinkedinConstants.class); 
    startActivity(t); 
    } 

     } 

回答

0

應用的錯誤處理,日誌記錄和調試適量。我沒有看到任何錯誤或失敗情況檢查。你的回調被稱爲?嘗試單步調試器。

雖然我對Linkedin開發有點新,但我對Android開發非常熟悉,並且已經獲得了Linkedin小工具在網上工作。在獲取授權令牌之前,您需要從Linkedin獲取一些驗證。這是回調起作用的地方。

我希望這能讓您朝着正確的方向前進。讓我們知道你發現了什麼。