2

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();
    }
}
Pratik
  • 30,639
  • 18
  • 84
  • 159
Rana.S
  • 2,265
  • 3
  • 20
  • 19

1 Answers1

4

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

dgn
  • 103
  • 5
  • 15
Adam Trachtenberg
  • 2,231
  • 1
  • 14
  • 18
  • Thanks for replying adam..adam can u tell me how to get access token. i have reached at user authentication. but i dont know the way how to get access token from browser to my android app for further process. – Rana.S Jun 23 '11 at 09:59
  • I got success to genrate access token and access secret. Can anyone tell how i can post a string from my android application at Linkedin account using share api. – Rana.S Jun 27 '11 at 06:23
  • @Rana.S. Are you able to update status ,if yes then please post your code – Tofeeq Ahmad Aug 06 '11 at 04:45