Question

I want to post image from SD Card with text to linkedIn from my android app.

I could share text but image is not sharing.

I tried with following code:

share.setOnClickListener(new OnClickListener() {
    @Override

     public void onClick(View v) {

            String share = et.getText().toString();
            if (null != share && !share.equalsIgnoreCase("")) {

                OAuthConsumer consumer = new CommonsHttpOAuthConsumer(Config.LINKEDIN_CONSUMER_KEY, Config.LINKEDIN_CONSUMER_SECRET);
                consumer.setTokenWithSecret(accessToken.getToken(), accessToken.getTokenSecret());

                DefaultHttpClient httpclient = new DefaultHttpClient();
                HttpPost post = new HttpPost("https://api.linkedin.com/v1/people/~/shares");
                try {
                    consumer.sign(post);
                } catch (OAuthMessageSignerException e) {
                    e.printStackTrace();
                } catch (OAuthExpectationFailedException e) {
                    e.printStackTrace();
                } catch (OAuthCommunicationException e) {
                    e.printStackTrace();
                } // here need the consumer for sign in for post the share
                post.setHeader("content-type", "text/XML");
                byte[] data = null;
             try {
            ileInputStream fis = new FileInputStream(imgUrl1);
            Bitmap bi = BitmapFactory.decodeStream(fis);
            ByteArrayOutputStream baos = new ByteArrayOutputStream()
                   bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            data = baos.toByteArray();  
            }
              catch (FileNotFoundException e) 
               { 
             e.printStackTrace();
         Log.d("onCreate", "debug error  e = " + e.toString());
           }     

         String myEntity = "<share><comment>"+  text +"</comment>    <content><submitted-image-url>data</submitted-image-url></content><visibility><code>anyone</code></visibility></share>";

              try {
                    post.setEntity(new StringEntity(myEntity));
                    org.apache.http.HttpResponse response = httpclient.execute(post);
                    Toast.makeText(LinkedInSampleActivity.this,
                            "Shared sucessfully", Toast.LENGTH_SHORT).show();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }else {
                Toast.makeText(LinkedInSampleActivity.this,
                        "Please enter the text to share",
                        Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Was it helpful?

Solution

In linkedIn you can't share the local images. For that you need to store the images in server and get the url of that image, now you can post the image to linkedIn...

This may help you...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top