像facebook上的Android facebook帖子在墙上

时间:2014-10-13 11:56:11

标签: android facebook post

我想像facebook这样的例子为facebook创建意图

Intent tweetIntent = new Intent(Intent.ACTION_SEND);
            tweetIntent.putExtra(Intent.EXTRA_TEXT, "some text");
            tweetIntent.setType("text/plain");

            PackageManager packManager = Model.getInstance().getContext().getPackageManager();
            List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,  PackageManager.MATCH_DEFAULT_ONLY);

            boolean resolved = false;
            for(ResolveInfo resolveInfo: resolvedInfoList){
                if(resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")){
                    tweetIntent.setClassName(
                        resolveInfo.activityInfo.packageName, 
                        resolveInfo.activityInfo.name );
                    resolved = true;
                    break;
                }
            }
            if(resolved){
                startActivity(tweetIntent);
            }else{
                Toast.makeText(Model.getInstance().getContext(), "Twitter app isn't found", Toast.LENGTH_SHORT).show();
            }    

我已经阅读了很多文章,我发现这种方式(intentIntent.putExtra(Intent.EXTRA_TEXT,“”))是不可能的Facebook。 所以我的问题如何才能实现我的目标?我只想将文字发布到用户的墙上。

3 个答案:

答案 0 :(得分:1)

根据FB新政策,它不允许在分享任何帖子时预先填写文本。用户必须手动输入发布内容。

参考: 视频:https://developers.facebook.com/docs/apps/review/prefill

文章:检查“2.让人控制” https://developers.facebook.com/policy/

文章:检查“第2步:添加发布逻辑” https://developers.facebook.com/docs/android/share

答案 1 :(得分:0)

  To just open user's FB so that the user can post.. You can try this. However if you want to post any text or link you need to use FB SDK and permissions. It is not possible via intents anymore.

Follow this Link

  Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, "Hiee.");
            sendIntent.setType("text/plain");
            sendIntent.setPackage("com.facebook.katana");
            try {
                startActivity(sendIntent);
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getApplicationContext(), "Install Facebook", 5000).show();
            }

答案 2 :(得分:0)

添加facebook SDK后! 在您的项目中

请查看以下简化示例代码:

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import com.facebook.android.*;
import com.facebook.android.Facebook.DialogListener;

public class FacebookActivity extends Activity implements DialogListener,
        OnClickListener
{

private Facebook facebookClient;
private LinearLayout facebookButton;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.test);//my layout xml

    facebookButton = (LinearLayout)this.findViewById(R.id.Test_Facebook_Layout);

}

@Override
public void onComplete(Bundle values)
{

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

    // 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", "this is a test");// 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)
{
    System.out.println("Error: " + e.getMessage());
}

@Override
public void onFacebookError(FacebookError e)
{
    System.out.println("Error: " + e.getMessage());
}

@Override
public void onCancel()
{
}

@Override
public void onClick(View v)
{
    if (v == facebookButton)
    {
        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);
    }
}

}

相关问题