后的图像与Android应用文本LinkedIn [英] post image with text to linkedIn from android app

查看:151
本文介绍了后的图像与Android应用文本LinkedIn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从SD卡上传图像与我的Andr​​oid应用文字LinkedIn。

我可以分享文本,但图像没有共享。

我试着用以下code:

  share.setOnClickListener(新OnClickListener(){
    @覆盖     公共无效的onClick(视图v){            。字符串份额= et.getText()的toString();
            如果(空=份额和放大器;!&安培;!share.equalsIgnoreCase()){                OAuthConsumer消费=新CommonsHttpOAuthConsumer(Config.LINKEDIN_CONSUMER_KEY,Config.LINKEDIN_CONSUMER_SECRET);
                consumer.setTokenWithSecret(accessToken.getToken(),accessToken.getTokenSecret());                DefaultHttpClient的HttpClient =新DefaultHttpClient();
                HttpPost后=新HttpPost(https://api.linkedin.com/v1/people/~/shares);
                尝试{
                    consumer.sign(岗位);
                }赶上(OAuthMessageSignerException E){
                    e.printStackTrace();
                }赶上(OAuthExpectationFailedException E){
                    e.printStackTrace();
                }赶上(OAuthCommunicationException E){
                    e.printStackTrace();
                } //这里需要的消费者登录后为股份
                post.setHeader(内容类型,文本/ XML);
                字节[]数据= NULL;
             尝试{
            ileInputStream FIS =新的FileInputStream(imgUrl1);
            位图双= BitmapFactory.de codeStream(FIS);
            ByteArrayOutputStream BAOS =新ByteArrayOutputStream()
                   bi.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS);
            数据= baos.toByteArray();
            }
              赶上(FileNotFoundException异常E)
               {
             e.printStackTrace();
         Log.d(的onCreate,调试误差e =+ e.toString());
           }         字符串myEntity所=&LT;共享和GT;&LT;注释和GT;+文字+&LT; /评论&GT; <content><submitted-image-url>data</submitted-image-url></content><visibility><$c$c>anyone</$c$c></visibility></share>\";              尝试{
                    post.setEntity(新StringEntity(myEntity所));
                    org.apache.http.Htt presponse响应= httpclient.execute(岗位);
                    Toast.makeText(LinkedInSampleActivity.this,
                            共享成功地,Toast.LENGTH_SHORT).show();
                }赶上(UnsupportedEncodingException五){
                    e.printStackTrace();
                }赶上(ClientProtocolException E){
                    e.printStackTrace();
                }赶上(IOException异常五){
                    e.printStackTrace();
                }
            }其他{
                Toast.makeText(LinkedInSampleActivity.this,
                        请输入文字分享
                        Toast.LENGTH_SHORT).show();
            }
        }
    });
}


解决方案

在LinkedIn,你不能共享本地图片。
对于您需要将图像存储在服务器上,并得到该图像的URL,现在你可以将图像发布到LinkedIn ...

这可能会帮助你...

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

解决方案

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...

这篇关于后的图像与Android应用文本LinkedIn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆