Java eclipse中的LinkedIn身份验证问题
我正在尝试将LinkedIn与android集成。使用教程,我应用了以下代码Java eclipse中的LinkedIn身份验证问题,java,android,eclipse,linkedin,Java,Android,Eclipse,Linkedin,我正在尝试将LinkedIn与android集成。使用教程,我应用了以下代码 private void setWebView() { LinkedinDialog.oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(LINKEDIN_CONSUMER_KEY, LINKEDIN_CONSUMER_SECRET); LinkedinDialog
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();
}
}
});
}
我得到以下错误在
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
我在互联网上搜索过,根据一些帖子,这是因为我有代理人。但我很确定我没有任何代理人。如果有人能告诉我该怎么办,我将不胜感激。
致以最诚挚的问候您很可能试图在不允许网络的UI线程上运行此程序。您需要在AsyncTask中实现oauth调用 在Android 3.0之前,用户界面线程上的网络调用是允许的。您正在学习的教程可能是在该更改发生之前编写的 --编辑--
要测试这是否正确,您可以尝试将应用程序目标设置为API 10,看看问题是否消失。好的,这就是我使用的,现在可以正常工作了
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
伟大的我使用的是完全相同的代码,但我一直得到“拒绝发布共享”的任何想法是什么导致的??我试图使用scope添加权限,但它只是被忽略了。我的应用程序在LinkedIn中运行良好,但我在带有冰淇淋三明治的设备上收到此错误。与服务提供商的通信失败:null。谁能帮帮我吗?