java - 适用于 Android 应用的 Linkedin Api 查询

标签 java android api android-widget linkedin-api

我想通过我的 Android 应用程序在 LinkedIn 更新部分发送数据。谁能告诉我建议,我应该从 linkedIn 询问哪个 API 以及如何在 UPDATES 部分上发布。我已与 LinkedIn API 建立连接并获得访问 token 。提前致谢。

以下代码是 LinkedIn 的访问 token 。

package com.sunilrana.translation;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLEncoder;

import java.util.List;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

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;

public class Linkedin extends Activity{

    private WebView mWebView;
    public static final String TAG= "Linkedin Client";
    public  String authUrl= null;
    private LinkedInOAuthService oauthService;
    private LinkedInRequestToken requestToken;
    private String consumerSecretValue;
    private String consumerKeyValue;

    @SuppressWarnings("unused")
    private String myurl;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.linkedin);


    mWebView = (WebView) findViewById(R.id.webkitWebView1);

    mWebView.setVerticalScrollBarEnabled(false);

    mWebView.setHorizontalScrollBarEnabled(false);


    mWebView.getSettings().setJavaScriptEnabled(true);

    try{
       consumerKeyValue = "MTLv7uAcYIM_tPhdoillSVoGQcrs59IiuZyO9neS08EGR7wNBINhp6nYHVLEm";

       consumerSecretValue = "qkwUWNWbznhjSTi1ubuOKLfYpBRiW52rBqN7OBD5u_mbVaEfTI1HEPpThfv";

        oauthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(consumerKeyValue, consumerSecretValue);

        System.out.println("Fetching request token from LinkedIn..."); 

        requestToken = oauthService.getOAuthRequestToken();

        authUrl = requestToken.getAuthorizationUrl();       

        mWebView.loadUrl(authUrl);

        mWebView.loadData(URLEncoder.encode("<html><body>    </body><html>").replaceAll("\\+"," "), "text/html",  authUrl);
        BufferedReader br = new BufferedReader(new  InputStreamReader(System.in));
       String pin = br.readLine();

       System.out.println("Fetching access token from LinkedIn...");                                                                              
       LinkedInAccessToken accessToken =  oauthService.getOAuthAccessToken(requestToken, pin);

      System.out.println("Access token: " +  accessToken.getToken());
       System.out.println("Token secret: " +  accessToken.getTokenSecret());

      final LinkedInApiClientFactory factory =  LinkedInApiClientFactory.newInstance(consumerKeyValue,  consumerSecretValue);
       final LinkedInApiClient client =  factory.createLinkedInApiClient(accessToken);

       System.out.println("Fetching profile for current user.");
       Person profile = client.getProfileForCurrentUser();
    }
    catch (Exception e){
        e.printStackTrace();
    }
}

最佳答案

最好使用的 API 是共享 API (link for Share API)。您可以仅传递状态消息、URL 或两者。

关于java - 适用于 Android 应用的 Linkedin Api 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6435228/

相关文章:

java - 当多个java客户端访问数据库时确保数据完整性

java - 我无法写入我创建的文本文件

android - 生成 Release APK 时出错。错误 : Duplicate resources; AAPT: error: resource string/app_name not found

android - 如何使用intent.createChooser android获取任何类型的文件

wordpress - 如何通过 Wordpress REST API 对 LearnDash 中 protected 数据的远程访问进行身份验证?

ruby-on-rails - Rails API 设计无需禁用 CSRF 保护

java - 从 java 代码运行 .JAR 文件 (netbeans)

java - 等到元素未找到或隐藏

android - 发长短信收错

api - 用于 REST API 调用的 Yii2 数据提供者