1

我正在为我的 Android 应用程序构建 LinkedIn 共享功能。我可以登录 LinkedIn,但之后模拟器显示空白屏幕。我究竟做错了什么?

这是代码,我的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);
    }

        }
4

1 回答 1

0

应用适当数量的错误处理、日志记录和调试。我没有看到检查任何错误或失败条件。你的回调被调用了吗?尝试单步调试调试器。

虽然我对 Linkedin 开发有点陌生,但我对 Android 开发非常熟悉,并且还让 Linkedin 小部件可以在 Web 上工作。在获取授权令牌之前,您需要从 Linkedin 取回一些验证。这就是回调发挥作用的地方。

我希望这能让你朝着正确的方向前进。让我们知道你发现了什么。

于 2012-04-18T07:23:04.693 回答