ssummeraw 2013-06-03 02:59 采纳率: 10%
浏览 3041
已采纳

eclipse 中的 LinkedIn 身份验证问题

我想使用 android 结合 LinkedIn。
使用的下面的代码:

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); 
05-23 17:32:08.026: E/AndroidRuntime(26733): FATAL EXCEPTION: main
05-23 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

我在网上查了说是因为在proxy下面的原因。但是我确定没有在 proxy下啊。请问是什么错误呢?

  • 写回答

1条回答

  • clcurie_11 2013-06-03 06:22
    关注

    我使用的解决方案:

    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();
        }
    }
    

    Libraries 是

    linkedin-j-android.jar
    signpost-jetty6-1.2.1.1.jar
    signpost-core-1.2.1.1.jar
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序