gpt4 book ai didi

java - LinkedIn 集成到 Android 应用程序中

转载 作者:行者123 更新时间:2023-12-01 05:22:19 25 4
gpt4 key购买 nike

我正在为我的 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);
}

}

最佳答案

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

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

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

关于java - LinkedIn 集成到 Android 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com