gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:57:54 25 4
gpt4 key购买 nike

我想从我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com