安卓Facebook意图

6
我正在使用这段代码在Facebook上发布内容,但它无法在官方Facebook应用程序中工作,因为它试图将内容发送为链接。有没有解决这个问题的方法?
Intent s = new Intent(android.content.Intent.ACTION_SEND);

s.setType("text/plain");
s.putExtra(Intent.EXTRA_SUBJECT, "Quote");
s.putExtra(Intent.EXTRA_TEXT, qoute);

startActivity(Intent.createChooser(s, "Quote"));

你能更详细地解释一下你的意思吗?你是指当你从分享菜单中选择Facebook应用程序时,EXTRA_TEXT字段是共享URL而不是分享消息吗? - matto1990
准确地说,我使用这个意图来通过短信、电子邮件、Twitter、Facebook等方式分享文本......问题是,如果我从弹出的选项中选择Facebook,"EXTRA_TEXT,引号"字符串会被共享为一个URL到Facebook上。这只发生在由开发者"Facebook"制作的Facebook应用程序中。 - zaid
1个回答

7

这是官方Facebook应用程序中的一个错误。我不得不使用Android Facebook SDK编写自己的活动来完成它。请参见下面的代码示例。

public class FacebookActivity extends Activity implements DialogListener
{

    private Facebook facebookClient;
    private LinearLayout facebookButton;
    private final String APP_API_ID = "XXXXXXXX";


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        facebookClient = new Facebook();
        // replace APP_API_ID with your own
        facebookClient.authorize(this, APP_API_ID,
            new String[] {"publish_stream", "read_stream", "offline_access"}, this);


    }

    @Override
    public void onComplete(Bundle values)
    {

        if (values.isEmpty())
        {
            //"skip" clicked ?

        }

        // if facebookClient.authorize(...) was successful, this runs
        // this also runs after successful post
        // after posting, "post_id" is added to the values bundle
        // I use that to differentiate between a call from
        // faceBook.authorize(...) and a call from a successful post
        // is there a better way of doing this?
        if (!values.containsKey("post_id"))
        {
            try
            {
                Bundle parameters = new Bundle();
                parameters.putString("message", "YOUR TEXT TO SHARE GOES HERE");// the message to post to the wall
                facebookClient.dialog(this, "stream.publish", parameters, this);// "stream.publish" is an API call


            }
            catch (Exception e)
            {
                // TODO: handle exception
                System.out.println(e.getMessage());
            }

        }

    }

    @Override
    public void onError(DialogError e)
    {       
        return;
    }

    @Override
    public void onFacebookError(FacebookError e)
    {   
        return;
    }

    @Override
    public void onCancel()
    {      
        return;     
    }

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接