![](/img/trans.png)
[英]how to post on facebook wall without dialog from android app?
[英]Post on Facebook wall without showing dialog on android
我正在嘗試在Facebook牆上張貼供稿,而無需使用Facebook Android SDK打開對話框。 我試圖找到一種方法,但是找不到。 任何人都可以告訴他們如何在不打開對話的情況下張貼到背景牆。
我嘗試使用以下代碼
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 *。
我也嘗試使用其他2種方法,但未發布任何內容
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();
}
});
}
據我所知,現在已經不推薦使用REST api來實現這一點... https://developers.facebook.com/docs/reference/rest/
編輯:這是您可以用來發布https://developers.facebook.com/docs/reference/rest/#publishing-methods的功能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.