Android facebook分享链接

时间:2014-04-20 08:32:33

标签: android facebook share

我有分享facebook链接的问题。我一直点击它说 "很遗憾,此页面无法使用。您是否收到了断开的链接或页面已被删除。"

public static final String FACEBOOK_SHARE_ACTION_LINK =" https://google.com&#34 ;; // =) 编辑 发布图片

    public class FacebookActivity extends Activity {
        private FacebookFacade facebook;
    private FacebookEventObserver facebookEventObserver;

    private TextView messageView;

    private String link;
    private String linkName;
    private String linkDescription;
    private String picture;
    private Map<String, String> actionsMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.ac_facebook);

        facebook = new FacebookFacade(this, Constants.FACEBOOK_APP_ID);
        facebookEventObserver = FacebookEventObserver.newInstance();

        messageView = (TextView) findViewById(R.id.message);
        TextView linkNameView = (TextView) findViewById(R.id.link_name);
        TextView linkDescriptionView = (TextView) findViewById(R.id.link_description);
        //Button postButton = (Button) findViewById(R.id.button_post);
        Button postImageButton = (Button) findViewById(R.id.button_post_image);

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            String message = bundle.getString(Extra.POST_MESSAGE);
            link = bundle.getString(Extra.POST_LINK);
            linkName = bundle.getString(Extra.POST_LINK_NAME);
            linkDescription = bundle.getString(Extra.POST_LINK_DESCRIPTION);
            picture = bundle.getString(Extra.POST_PICTURE);
            actionsMap = new HashMap<String, String>();
            actionsMap.put(Constants.FACEBOOK_SHARE_ACTION_NAME, Constants.FACEBOOK_SHARE_ACTION_LINK);

            messageView.setText(message);
            linkNameView.setText(linkName);
            linkDescriptionView.setText(linkDescription);
        }


        postImageButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (facebook.isAuthorized()) {
                    publishImage();
                    finish();
                } else {
                    // Start authentication dialog and publish image after successful authentication
                    facebook.authorize(new AuthListener() {
                        @Override
                        public void onAuthSucceed() {
                            publishImage();
                            finish();
                        }

                        @Override
                        public void onAuthFail(String error) { // Do noting
                        }
                    });
                }
            }
        });
    }

    //private void publishMessage() {
        //facebook.publishMessage(messageView.getText().toString(), link, linkName, linkDescription, picture, actionsMap);
    //}

    private void publishImage() {
        Bitmap bmp = ((BitmapDrawable) getResources().getDrawable(R.drawable.howmuchcanufarm)).getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] bitmapdata = stream.toByteArray();
        facebook.publishImage(bitmapdata, Constants.FACEBOOK_SHARE_IMAGE_CAPTION);
    }

    @Override
    public void onStart() {
        super.onStart();
        facebookEventObserver.registerListeners(this);
        if (!facebook.isAuthorized()) {
            facebook.authorize();
        }
    }

    @Override
    public void onStop() {
        facebookEventObserver.unregisterListeners();
        super.onStop();
    }


}

0 个答案:

没有答案