Skip to main content

ANDROID - update status Linked-IN


jars:

1. linkedin-j-android.jar
2. scribe-1.3.1.jar

MainActivity:

 package com.testshare;  
 import java.util.EnumSet;  
 import org.scribe.oauth.OAuthService;  
 import android.app.Activity;  
 import android.content.Intent;  
 import android.os.Bundle;  
 import android.util.Log;  
 import com.google.code.linkedinapi.client.LinkedInApiClient;  
 import com.google.code.linkedinapi.client.LinkedInApiClientFactory;  
 import com.google.code.linkedinapi.client.enumeration.NetworkUpdateType;  
 import com.google.code.linkedinapi.schema.Network;  
 public class TestshareActivity extends Activity {  
        private int LINKEDIN_OAUTH_RESULT_CODE = 4000;  
        private OAuthService service;  
        private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~";  
        /** Called when the activity is first created. */  
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
               super.onCreate(savedInstanceState);  
               setContentView(R.layout.main);  
               click();  
        }  
        public void click() {  
               Intent intent = new Intent(TestshareActivity.this,  
                             LinkedInOAuthActivity.class);  
               startActivityForResult(intent, LINKEDIN_OAUTH_RESULT_CODE);  
        }  
        @Override  
        protected void onRestart() {  
               // TODO Auto-generated method stub  
               shareText_new();  
               super.onRestart();  
        }  
        private void shareText_new() {  
               // String scopeParams = "rw_nus+r_basicprofile";  
               // TODO Auto-generated method stub  
               try {  
                      final LinkedInApiClientFactory factory = LinkedInApiClientFactory  
                                    .newInstance(generalClass.APIKEY, generalClass.APISECRET);  
                      final LinkedInApiClient client = factory.createLinkedInApiClient(  
                                    generalClass._Token1, generalClass._Secret1);  
                      client.postNetworkUpdate("hello DJ-android.blogspot.com");  
                      System.out  
                                    .println("Your update has been posted. Check the LinkedIn site for confirmation.");  
                      System.out.println("Fetching your network updates of type:"  
                                    + NetworkUpdateType.STATUS_UPDATE);  
                      Network network = client.getNetworkUpdates(EnumSet  
                                    .of(NetworkUpdateType.STATUS_UPDATE));  
                      // printResult(network);  
               } catch (Exception e) {  
                      // TODO: handle exception  
                      Log.e("error share st--->", "" + e.getMessage().toString());  
               }  
        }  
 }  

LinkedInOAuthActivity

 package com.testshare;  
 import android.app.Activity;  
 import android.content.Intent;  
 import android.net.Uri;  
 import android.os.AsyncTask;  
 import android.os.Bundle;  
 import android.util.Log;  
 import android.webkit.WebView;  
 import android.webkit.WebViewClient;  
 import org.scribe.builder.ServiceBuilder;  
 import org.scribe.builder.api.LinkedInApi;  
 import org.scribe.exceptions.OAuthException;  
 import org.scribe.model.*;  
 import org.scribe.oauth.*;  
 public class LinkedInOAuthActivity extends Activity {  
        private WebView mWebView = null;  
        private OAuthService mService = null;  
        private Token mRequestToken = null;  
        String scopeParams = "rw_nus+r_baseprofile";  
        String scopeParams1 = "rw_nus";  
        @Override  
        public void onCreate(Bundle savedInstanceState) {  
               super.onCreate(savedInstanceState);  
               setContentView(R.layout.linkedin_oauth);  
               mService = new ServiceBuilder().provider(LinkedInApi.class)  
                             .apiKey(generalClass.APIKEY).apiSecret(generalClass.APISECRET)  
                             .callback(generalClass.CALLBACK).scope(scopeParams1).build();  
               Log.e("mService----->", "" + mService);  
               mWebView = (WebView) findViewById(R.id.linkedin_webview);  
               // Start the async task  
               LinkedInAuthTask task = new LinkedInAuthTask();  
               task.execute();  
        }  
        // Async task for authentication  
        private class LinkedInAuthTask extends AsyncTask<Void, Void, String> {  
               @Override  
               protected String doInBackground(Void... arg0) {  
                      // Temporary URL  
                      String authURL = "http://api.linkedin.com/";  
                      try {  
                             mRequestToken = mService.getRequestToken();  
                             Log.e("mRequestToken----->", "" + mRequestToken);  
                             // mService.getAccessToken(arg0, arg1)  
                             authURL = mService.getAuthorizationUrl(mRequestToken);  
                             Log.e("authURL----->", "" + authURL);  
                      } catch (OAuthException e) {  
                             e.printStackTrace();  
                             return null;  
                      }  
                      return authURL;  
               }  
               @Override  
               protected void onPostExecute(String authURL) {  
                      mWebView.setWebViewClient(new WebViewClient() {  
                             @Override  
                             public boolean shouldOverrideUrlLoading(WebView view, String url) {  
                                    super.shouldOverrideUrlLoading(view, url);  
                                    if (url.startsWith("oauth")) {  
                                           mWebView.setVisibility(WebView.GONE);  
                                           final String url1 = url;  
                                           Thread t1 = new Thread() {  
                                                  public void run() {  
                                                         Uri uri = Uri.parse(url1);  
                                                         String verifier = uri  
                                                                       .getQueryParameter("oauth_verifier");  
                                                         Log.e("verifier----->", "" + verifier);  
                                                         generalClass._verifier = verifier;  
                                                         Verifier v = new Verifier(verifier);  
                                                         Token accessToken = mService.getAccessToken(  
                                                                       mRequestToken, v);  
                                                         // Token accessToken1 =  
                                                         // request.getSession().setAttribute("requestToken",  
                                                         // v);  
                                                         Log.e("accessToken.getToken()----->", ""  
                                                                       + accessToken.getToken());  
                                                         Log.e("accessToken.getSecret()----->", ""  
                                                                       + accessToken.getSecret());  
                                                         // Token a = accessToken;  
                                                         generalClass._Token = accessToken;  
                                                         generalClass._Token1 = accessToken.getToken();  
                                                         generalClass._Secret1 = accessToken.getSecret();  
                                                         Intent intent = new Intent();  
                                                         intent.putExtra("access_token",  
                                                                       accessToken.getToken());  
                                                         intent.putExtra("access_secret",  
                                                                       accessToken.getSecret());  
                                                         setResult(RESULT_OK, intent);  
                                                         finish();  
                                                  }  
                                           };  
                                           t1.start();  
                                    }  
                                    return false;  
                             }  
                      });  
                      mWebView.loadUrl(authURL);  
               }  
        }  
 }  

linkedin_oauth.xml

 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        android:layout_width="fill_parent" android:layout_height="fill_parent"  
        android:orientation="vertical">  
        <WebView android:id="@+id/linkedin_webview" android:focusable="true"  
               android:scrollbars="vertical" android:layout_width="match_parent"  
               android:layout_height="match_parent"></WebView>  
 </LinearLayout>  

extraClass

 package com.testshare;  
 import org.scribe.model.Token;  
 public class generalClass {  
        public final static String APIKEY = "linkedin API KEY";  
        public final static String APISECRET = "linkedin API SECRET";  
        public final static String CALLBACK = "oauth://linkedin";  
        public static String _verifier;  
        public static Token _Token;  
        public static String _Secret;  
        public static String _Token1;  
        public static String _Secret1;  
 }  

manifest File

 <?xml version="1.0" encoding="utf-8"?>  
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
        package="com.testshare" android:versionCode="1" android:versionName="1.0">  
        <uses-sdk android:maxSdkVersion="13" android:minSdkVersion="8" />  
        <uses-permission android:name="android.permission.INTERNET"></uses-permission>  
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>  
        <application android:icon="@drawable/icon" android:label="@string/app_name">  
               <activity android:name=".TestshareActivity" android:label="@string/app_name">  
                      <intent-filter>  
                             <action android:name="android.intent.action.MAIN" />  
                             <category android:name="android.intent.category.LAUNCHER" />  
                      </intent-filter>  
               </activity>  
               <activity android:name=".LinkedInOAuthActivity"  
                      android:theme="@android:style/Theme.Light" android:configChanges="keyboardHidden|orientation"></activity>  
        </application>  
 </manifest>  

reference links:

http://code.google.com/p/linkedin-j/source/browse/trunk/linkedin-j/core/src/examples/java/com/google/code/linkedinapi/client/examples/PostNetworkUpdateExample.java?r=197

http://stackoverflow.com/questions/15082693/android-update-status-linked-in-in-apps-background

https://github.com/fernandezpablo85/scribe-java

http://stackoverflow.com/questions/12188341/cant-post-anything-on-linkedin-using-linkedin-j

Comments

  1. Hi,
    i am getting the exception at this line,
    client.postNetworkUpdate("hello DJ-android.blogspot.com");


    Please provide the solution ASAP.
    Thank

    ReplyDelete
    Replies
    1. which type of exception you got?? Please show me error Logs.

      Delete
    2. It is working fine
      But updates are not posted onto LinkedIn.
      What are the library's i need to add.

      Delete
    3. 04-17 17:01:32.446: E/error share st--->(27313): Throttle limit for calls to this resource is reached.

      after repeated posts i am getting this exception.

      Please give the clarification,Thank You.

      Delete
  2. hi Dhaval Sodha parmar i'm getting thid kind of Exception can u guide me where i'm doing wrong..plz

    05-14 12:02:36.888: I/dalvikvm(395): Could not find method com.google.code.linkedinapi.client.LinkedInApiClientFactory.newInstance, referenced from method com.testshare.TestshareActivity.shareText_new
    05-14 12:02:36.897: W/dalvikvm(395): VFY: unable to resolve static method 3395: Lcom/google/code/linkedinapi/client/LinkedInApiClientFactory;.newInstance (Ljava/lang/String;Ljava/lang/String;)Lcom/google/code/linkedinapi/client/LinkedInApiClientFactory;
    05-14 12:02:36.897: D/dalvikvm(395): VFY: replacing opcode 0x71 at 0x0004
    05-14 12:02:36.947: D/dalvikvm(395): VFY: dead code 0x0007-003b in Lcom/testshare/TestshareActivity;.shareText_new ()V
    05-14 12:02:37.507: E/mService----->(395): org.scribe.oauth.OAuth10aServiceImpl@45f55d60
    05-14 12:02:43.997: D/dalvikvm(395): GC_FOR_MALLOC freed 4962 objects / 278464 bytes in 93ms
    05-14 12:02:44.537: E/mRequestToken----->(395): Token[3b901ab4-b99f-46f9-901f-06d5a58833e3 , 96e587ee-3254-4453-91bc-98e4a5e375cc]
    05-14 12:02:44.537: E/authURL----->(395): https://api.linkedin.com/uas/oauth/authorize?oauth_token=3b901ab4-b99f-46f9-901f-06d5a58833e3
    05-14 12:03:39.047: E/accessToken.getToken()----->(395): 51ae571b-1263-42f7-8e0b-c93dfef508af
    05-14 12:03:39.047: E/accessToken.getSecret()----->(395): b0e061d1-0d0f-47b9-9dce-12b6fcf527bc
    05-14 12:03:39.097: D/NativeCrypto(395): Freeing OpenSSL session
    05-14 12:03:39.117: D/AndroidRuntime(395): Shutting down VM
    05-14 12:03:39.117: W/dalvikvm(395): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    05-14 12:03:39.167: E/AndroidRuntime(395): FATAL EXCEPTION: main
    05-14 12:03:39.167: E/AndroidRuntime(395): java.lang.NoClassDefFoundError: com.google.code.linkedinapi.client.LinkedInApiClientFactory
    05-14 12:03:39.167: E/AndroidRuntime(395): at com.testshare.TestshareActivity.shareText_new(TestshareActivity.java:39)
    05-14 12:03:39.167: E/AndroidRuntime(395): at com.testshare.TestshareActivity.onRestart(TestshareActivity.java:31)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.app.Instrumentation.callActivityOnRestart(Instrumentation.java:1139)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.app.Activity.performRestart(Activity.java:3805)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.app.Activity.performResume(Activity.java:3816)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2059)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.os.Handler.dispatchMessage(Handler.java:99)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.os.Looper.loop(Looper.java:123)
    05-14 12:03:39.167: E/AndroidRuntime(395): at android.app.ActivityThread.main(ActivityThread.java:4627)
    05-14 12:03:39.167: E/AndroidRuntime(395): at java.lang.reflect.Method.invokeNative(Native Method)
    05-14 12:03:39.167: E/AndroidRuntime(395): at java.lang.reflect.Method.invoke(Method.java:521)
    05-14 12:03:39.167: E/AndroidRuntime(395): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    05-14 12:03:39.167: E/AndroidRuntime(395): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    05-14 12:03:39.167: E/AndroidRuntime(395): at dalvik.system.NativeStart.main(Native Method)

    ReplyDelete
  3. i'm getting this kind of error what is this "Throttle limit for calls to this resource is reached."

    ReplyDelete
  4. Yes ...it's working but can't see post on LinkedIn.

    ReplyDelete
  5. According to LinkedIn documentation->

    This is the only API that has a whitelist. While your application is in beta mode, network updates you send are posted only to the developers on your whitelist who are also first degree connections. When you indicate that your application is live, network updates will then go to the entire first degree connections list of the user who posts them.

    So make your App Live

    ReplyDelete
  6. according to documentation:-

    Whitelist

    This is the only API that has a whitelist. While your application is in beta mode, network updates you send are posted only to the developers on your whitelist who are also first degree connections. When you indicate that your application is live, network updates will then go to the entire first degree connections list of the user who posts them.

    You toggle your application's status between Development or Live by visiting the API Provisioning page and setting the Application Status field. You can also add and remove developers to your application on that page.

    ReplyDelete

Post a Comment

Popular posts from this blog

MCP vs CLI: Which One Fits Your AI Agent's Job?

  Every AI agent that touches the outside world does it one of two ways: it runs a shell command, or it calls a tool through the Model Context Protocol. Both get the job done, but they don't cost the same or fail the same way, which is why "MCP vs CLI" keeps resurfacing without resolving. I want to answer it for the cases that matter most: plain developer tooling, data-heavy systems like banking, forecasting pipelines, and transaction automation like billing or booking. Neither wins outright. Where you draw the line is the actual skill. Key Takeaways CLI is the default for anything the model already knows cold, git, file ops, text processing, since there's no schema tax and commands chain through pipes. MCP earns its cost when a system needs per-user auth, audit trails, or access to sources the model can't otherwise reach, exactly what regulated systems like banking require. Transaction automation works best split: deterministic code drives the repeatable steps, a...

ANDROID - Adding ActionBar Navigation Tabs

Note: if you are develop App < 3.0 Android OS then use  ActionBarSherlock   support library. ActionBarSherlock is an extension of the  support library  designed to facilitate the use of the action bar design pattern across all versions of Android with a single API. Create new Android Project : in Main Activity package com.AlarmManager; import android.os.Bundle; import android.view.View; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.Tab; import com.actionbarsherlock.app.SherlockFragmentActivity; public class AlarmManagerActivity extends SherlockFragmentActivity { public static String ACTIVE_TAB = "activeTab"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { setTheme(R.style.Theme_Sherlock_Light_DarkActionBar); super.onCreate(savedInstanceState); // s...

Don't Ship AI Agent Skills Without Evals

At the AI Engineer World's Fair on July 1, 2026, Philipp Schmid, a Staff Engineer on the Gemini API and agents team at Google DeepMind, asked a room full of engineers a simple question: who uses skills with their coding agents? Every hand went up. Who has evals for those skills? Almost none. That gap is the entire talk, which Schmid also wrote up on his own blog, philschmid.de/testing-skills . His team indexed the skills ecosystem through SkillsBench and found the same pattern everywhere: people ship a SKILL.md file after two manual test runs and move on. It looks fine in a demo. It quietly corrupts outputs in production, because bad skills don't crash. They just make the agent confidently wrong. If you've already read our breakdown of Matt Pocock's Claude Code skills library , think of this as the other half of that story: what happens once you've installed a skill and it's actually running against real prompts. Key Takeaways SkillsBench indexed 47,000+ un...