【问题标题】:Android Facebook Intent安卓 Facebook 意图
【发布时间】:2010-08-13 22:26:34
【问题描述】:

我正在使用此代码在 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 而不是共享消息?
  • 非常。我使用此意图通过短信、电子邮件、twitter、facebook 等共享文本......问题是,如果我从弹出选择中选择 facebook,则“EXTRA_TEXT,qoute”字符串将作为 url 共享给 facebook。这只发生在开发者“facebook”的 facebook 应用程序中。

标签: android facebook


【解决方案1】:

这是官方 Facebook 应用程序中的错误。我必须使用 Facebook SDK for Android 编写自己的活动代码。请参阅下面的代码示例。

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多