gpt4 book ai didi

android - 在 Facebook 墙上发帖而不在 android 上显示对话框

转载 作者:太空狗 更新时间:2023-10-29 16:42:44 25 4
gpt4 key购买 nike

我正在尝试使用 Facebook Android SDK 在不打开对话框的情况下在 Facebook 墙上发布提要。我试图找到一种方法,但找不到。谁能告诉他们如何在不打开对话的情况下在后台发布到墙上。

我尝试使用下面的代码

public static void PublishToFeedInBackground()
{
final Bundle _postParameter = new Bundle();
_postParameter.putString("name", name);
_postParameter.putString("link", link);
_postParameter.putString("picture", link_to_image);
_postParameter.putString("caption", caption);
_postParameter.putString("description", description);

final List<String> PERMISSIONS = Arrays.asList("publish_actions");

if (Session.getActiveSession() != null)
{
// Check for publish permissions
List<String> _permissions = Session.getActiveSession().getPermissions();
if (!isSubsetOf(PERMISSIONS, _permissions))
{
NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this.GetContext(), PERMISSIONS);
Session.getActiveSession().requestNewReadPermissions(reauthRequest);
return;
}
}

this.runOnUiThread(new Runnable()
{
@Override
public void run()
{
Request request = new Request(Session.getActiveSession(), "me/feed", _postParameter, HttpMethod.POST);

RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
});
}

但它发布了我的应用页面详细信息,而不是我提供的 *_postParameter*。

我也尝试过使用其他两种方法,但它没有发布任何内容

    Map<String, Object> params = new HashMap<String, Object>();
params.put("name", name);
params.put("link", link);
params.put("picture", link_to_image);
params.put("caption", caption);
params.put("description", description);

JSONObject jfeed = new JSONObject(params);
final GraphObject _feed = GraphObject.Factory.create(jfeed);

Request.executePostRequestAsync(Session.getActiveSession(), "https://graph.facebook.com/"+userID+"/feed", _feed, new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
Log.i("tag", response.toString());
}
});

第二种方法是

Request.executeRestRequestAsync(Session.getActiveSession(), "stream.publish", _postParameter, HttpMethod.POST);

最佳答案

我发现了问题所在。我没有要求正确的权限,图形路径也是错误的。正确的方法是:

public static void PublishToFeedInBackground()
{

final Bundle _postParameter = new Bundle();
_postParameter.putString("name", name);
_postParameter.putString("link", link);
_postParameter.putString("picture", link_to_image);
_postParameter.putString("caption", caption);
_postParameter.putString("description", description);

final List<String> PERMISSIONS = Arrays.asList("publish_stream");

if (Session.getActiveSession() != null)
{
NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this.GetContext(), PERMISSIONS);
Session.getActiveSession().requestNewPublishPermissions(reauthRequest);
}

this.runOnUiThread(new Runnable()
{
@Override
public void run()
{
Request request = new Request(Session.getActiveSession(), "feed", _postParameter, HttpMethod.POST);

RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
});
}

关于android - 在 Facebook 墙上发帖而不在 android 上显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15091591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com