How to use BatchRequest for different friend feed posts

326 views
Skip to first unread message

Neeli

unread,
Aug 7, 2011, 7:42:19 PM8/7/11
to RestFB
Hi,

I have a use case where I need to post a bunch of feeds to users walls
on facebook. I have a facebook token for each user. I was trying to
reach BatchRequest for this and looks like I cannot. A batch request
has only 1 facebook token associated to it. So I can only do multiple
requests for a single user only. Can someone confirm this?

My code looks like this..

List<BatchRequest> batchReqs = new ArrayList<BatchRequest> ();
for (MyClass e : friends) {
String friendId = e.get("id");
String message = e.getMessage();
BatchRequest bReq = new BatchRequest.BatchRequestBuilder(friendId
+"/feed").method("POST").body(Parameter.with("message",
message)).build();
batchReqs.add(bReq);
}
List<BatchResponse> batchRes = _fbClient.executeBatch(batchReqs,
null);

Here fbClient is a instance of DefacebookClient which has a facebook
token. In the above code, I am trying to post to multiple friends (who
have different access tokens) in a batch but batchrequest seems to
take only one token. I guess I am trying to do that's not feasible
with graph API??

Thanks
Neeli

Mark Allen

unread,
Aug 8, 2011, 9:28:16 AM8/8/11
to RestFB
You may specify an access_token parameter at the batch request level
which will override the "global" access_token you pass along to the
DefaultFacebookClient constructor.

See the "Specifying different access tokens for different operations"
section of https://developers.facebook.com/docs/reference/api/batch/.
I haven't tried this myself but I believe it should work.

Thanks
Mark

Neeli

unread,
Aug 8, 2011, 11:12:19 AM8/8/11
to RestFB
Thanks Mark. I looked at RestFB javadoc for all Batch API
(BatchRequest & BatchRequestBuilder) and I couldn't find a way to set
access token at each request level in a batch. Does the API support
it? Or should we directly interact with facebook API to achieve this?

Thanks
Neeli

On Aug 8, 6:28 am, Mark Allen <m...@xmog.com> wrote:
> You may specify an access_token parameter at the batch request level
> which will override the "global" access_token you pass along to the
> DefaultFacebookClient constructor.
>
> See the "Specifying different access tokens for different operations"
> section ofhttps://developers.facebook.com/docs/reference/api/batch/.

Neeli

unread,
Aug 8, 2011, 11:25:26 AM8/8/11
to RestFB
Sorry. I think the facebook API is clear. The facebook doc says it
could be "a query string or form post parameter". I guess I could add
access_token as additional parameter using the Parameter interface.

Thanks
Neeli

Mark Allen

unread,
Aug 8, 2011, 11:25:57 AM8/8/11
to RestFB
There is no specific builder method for access_token - for more
flexibility, there's a general-purpose parameters(Parameter...)
method. You can use it like this:

BatchRequest postRequest = new BatchRequestBuilder("me/feed")
.method("POST")
.body(Parameter.with("message", "Testing!"))
.parameters(Parameter.with("access_token", "XXX"),
Parameter.with("something","else"))
.build();

HTH

Mark

Neeli

unread,
Aug 8, 2011, 2:11:10 PM8/8/11
to RestFB
Thanks a lot. That works.

Neeli
Reply all
Reply to author
Forward
0 new messages