适用于 Android 应用的 Linkedin Api 查询

发布于 2024-11-16 17:06:09 字数 3441 浏览 2 评论 0原文

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

LinkedIn 的访问令牌代码如下。

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

I want to send data through my android application on LinkedIn update section. Can anyone tell me suggestion which API i should ask from linkedIn and how it possible to post on UPDATES Section. I have made connection with LinkedIn API and got Access Token. Thanks in Advance.

Code is following for Access Token for LinkedIn.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

智商已欠费 2024-11-23 17:06:09

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

Best API to use is the Share API (link for Share API) . You can pass just a status message, a URL, or both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文