Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I encode the & symbol for batch requests?

I have a Facebook batch request that looks like this:

https://graph.facebook.com/?access_token=ACCESS_TOKEN&batch=[{"method": "GET", "relative_url": "[email protected]&type=user"}]

Sending this across the wire returns:

{"error"=>0, "error_description"=>"batch parameter must be a JSON array"} 

If I remove the &type=user, it works fine (sends back an empty data array). I am absolutely certain that Facebook is not parsing the & character correctly. I read online somewhere that I could try encoding the & symbol to %26, however using that replacement seems to instead do a query for "[email protected]%26type=user". If you reverse the order of the parameters, you will see what I mean.

Any ideas how I can get the batch request parser on Facebook to recognize the & symbol without filing a bug report that will never be fixed?

EDIT:

I am using URI.encode. Here is the exact code:

    queries = email_array.map { |email| { :method => "GET", :relative_url => "search?q=#{email}&type=user" } }
    route = "https://graph.facebook.com/?access_token=#{token}&batch=#{URI.encode(queries.to_json)}"
    res = HTTParty.post(route)
like image 302
VNO Avatar asked Dec 10 '25 14:12

VNO


1 Answers

After actually playing around with this some more, I managed to reproduce the same behavior, even with a careful check and double-check that I was following the api specs correctly. This looks like a bug in facebook's batch method -- it doesn't understand ampersands in param values correctly.

like image 57
Ben Lee Avatar answered Dec 12 '25 03:12

Ben Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!