java - 从 Android 应用程序将带有文本的图像发布到 linkedIn

标签 java android linkedin

我想从我的 Android 应用程序将带有文本的 SD 卡图像发布到 linkedIn。

我可以分享文字,但无法分享图片。

我尝试了以下代码:

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

最佳答案

在 linkedIn 中你不能分享本 map 片。 为此,您需要将图像存储在服务器中并获取该图像的 url,现在您可以将图像发布到 linkedIn...

这可能对你有帮助...

关于java - 从 Android 应用程序将带有文本的图像发布到 linkedIn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22984625/

相关文章:

android - 无法移开或删除现有 objective-c :\androidSDK\sdk\tools

java - 安卓 : OpenCv comparing two images issue

java - 客户端-服务器编程中出现错误

java - 二维(并发)HashMap : 2-property key type? hashmap of hashmaps? [更新]

java - Keytool 给出错误的 android apk 哈希码

java - 使用 Android 创建强密码生成器

javascript - 如何在不滚动的情况下触发滚动事件

integration - 如何获得 LinkedIn r_fullprofile 访问权限?

linkedin - 如何报告LinkedIn API中的错误?

java - 用于简单图像编辑的 SWING 组件