我是android新手。在我的应用程序中,有一个要求是,当我点击分享按钮时,我需要分享墙上挂着的东西。我该怎么办?请任何人都可以帮助我。如何在android上发布消息在linkedin上?
感谢提前。
我是android新手。在我的应用程序中,有一个要求是,当我点击分享按钮时,我需要分享墙上挂着的东西。我该怎么办?请任何人都可以帮助我。如何在android上发布消息在linkedin上?
感谢提前。
那么我使用socialauth for android在linkedin和twitter上发布我的消息。
和更基本的方式你可以通过this
下面是socialauth一个例子:
首先,你必须从here
下载socialauth-android-sdk-2.0.zip然后从dist文件夹复制jar并将其粘贴到项目的libs文件夹中。
现在,
上linkedin注册应用程序,并从拉链的资产文件夹到你的项目的资产文件夹API密钥和秘密密钥
复制文件“oauth_consumer.properties”,还可以编辑这个文件,在linkedin部分编写你的API密钥和秘密密钥
#LinkedIn
api.linkedin.com.consumer_key = *************
api.linkedin.com.consumer_secret = **************
也可以从zip示例文件夹中提供的任何示例获取linkedin的drawable。
最后,相应地改变你的活动(如下活动),
public class ShareActivity extends Activity implements OnClickListener {
EditText shareText;
SocialAuthAdapter shareAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share_layout);
button = (Button) findViewById(R.id.share);
button.setOnClickListener(this);
ImageView product_image = (ImageView) findViewById(R.id.share_image);
shareText = (EditText) findViewById(R.id.share_text);
shareAdapter = new SocialAuthAdapter(new ResponseListener());
shareAdapter.addProvider(Provider.LINKEDIN, R.drawable.linkedin);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.share:
shareAdapter.authorize(this, Provider.LINKEDIN);
break;
}
}
private final class ResponseListener implements DialogListener {
@Override
public void onComplete(Bundle values) {
shareAdapter.updateStatus(shareText.getText().toString());
Toast.makeText(getApplicationContext(), "Message Posted",
Toast.LENGTH_SHORT).show();
}
@Override
public void onError(SocialAuthError e) {
Log.v("Share", "OMG ERROR!!!!" + e.getMessage());
}
@Override
public void onCancel() {
// Toast.makeText(Share.this, "Cancelled",
// Toast.LENGTH_SHORT).show();
}
@Override
public void onBack() {
// Toast.makeText(Share.this, "Back", Toast.LENGTH_SHORT).show();
}
}
}
利用这一点,它可以通过什么也没有发生socialauth例如解决您的问题
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();
}
}
});
}
。 – suman 2013-05-17 09:36:14
等一下我会用一个例子编辑我的答案 – 2013-05-17 09:45:04
但是,我怎样才能发表在脸书和微博。 – suman 2013-05-18 08:28:13