0

我是 android 新手。在我的应用程序中,有一个要求是,当我点击分享按钮时,我需要在墙上的链接上分享一些东西。我该怎么办?请任何人都可以帮助我。

提前致谢。

4

2 回答 2

1

好吧,我正在使用socialauth for android在linkedin 和twitter 上发布我的消息。

对于更基本的方法,你可以通过这个

这是 socialauth 的示例:

首先你必须从这里下载 socialauth-android-sdk-2.0.zip

然后从 dist 文件夹中复制 jar 并将其粘贴到项目的 libs 文件夹中。

现在,

在linkedin上注册您的应用程序并获取API密钥和密钥

将文件“oauth_consumer.properties”从 zip 的 assets 文件夹复制到项目的 assets 文件夹,并编辑此文件并将您的 API 密钥和密钥写入linkedin 部分

#LinkedIn
api.linkedin.com.consumer_key = *************
api.linkedin.com.consumer_secret = **************

还可以从 zip 的示例文件夹中提供的任何示例中获取可绘制的linkedin。

最后,相应地更改您的活动(下面给出的活动),

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

    }

}
于 2013-05-14T12:30:20.520 回答
0

使用这个,它可以解决你的问题

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

}

于 2015-07-08T06:05:46.243 回答