I'm developing a messenger bot for facebook graph API and I want to sent batched requests with id. However, at some point, Facebook just doesn't catch them.
The documentation is not very helpful (the only thing I found: https://developers.facebook.com/docs/graph-api/making-multiple-requests)
The point is, I'm sending such a request to API (one batched request for demo purposes):
URL : https://graph.facebook.com/v2.6/
Headers:
Content-Type: application/json
Body:
access_token=XXXXXXX&batch=[{"method":"POST","headers":{"name":"Content-Type","value":"application/json; charset=UTF-8"},"relative_url":"me/messages","body":"%7B%22recipient%22%3A%7B%22id%22%3A%22YYYYY%22%7D%2C%22message%22%3A%7B%22attachment%22%3A%7B%22type%22%3A%22template%22%2C%22payload%22%3A%7B%22template_type%22%3A%22generic%22%2C%22elements%22%3A%5B%7B%22title%22%3A%22test%22%2C%22subtitle%22%3A%22test%20test%22%2C%22item_url%22%3A%22%22%2C%22image_url%22%3A%22https%3A%2F%2Fdata.fideinc.com%2Fcustom%2Fent_19286B%2Fid_1ABEA3C_image.png%22%2C%22buttons%22%3A%5B%7B%22type%22%3A%22element_share%22%7D%2C%7B%22type%22%3A%22postback%22%2C%22title%22%3A%22%5Cud83e%5Cudd11%20%5Cu0410%5Cu043a%5Cu0446%5Cu0438%5Cu0438%20%5Cu0432%20%5Cu0437%5Cu0430%5Cu0432%5Cu0435%5Cu0434%5Cu0435%5Cu043d%5Cu0438%5Cu0438%22%2C%22payload%22%3A%22offers%22%7D%5D%7D%5D%2C%22image_aspect_ratio%22%3A%22horizontal%22%7D%7D%7D%2C%22tag%22%3Anull%7D","access_token":"XXXXXXX"}]
Whatever format I used for the body element, it just responds: "{\"error\":{\"message\":\"(#100) The parameter recipient is required\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"AHiM+KytmHB\"}}"
For every body element.
Other body encodings I tried:
"{\"recipient\":{\"id\":\"YYYYY\"},\"message\":{\"attachment\":{\"type\":\"template\",\"payload\":{\"template_type\":\"generic\",\"elements\":[{\"title\":\"test\",\"subtitle\":\"test test\",\"item_url\":\"\",\"image_url\":\"https://data.fideinc.com/custom/ent_19286B/id_1ABEA3C_image.png\",\"buttons\":[{\"type\":\"element_share\"},{\"type\":\"postback\",\"title\":\"\\ud83e\\udd11 \\u0410\\u043a\\u0446\\u0438\\u0438 \\u0432 \\u0437\\u0430\\u0432\\u0435\\u0434\\u0435\\u043d\\u0438\\u0438\",\"payload\":\"offers\"}]}],\"image_aspect_ratio\":\"horizontal\"}}},\"tag\":null}"
messages=%257B%2522recipient%2522%253A%257B%2522id%2522%253A%2522YYYYY%2522%257D%252C%2522message%2522%253A%257B%2522attachment%2522%253A%257B%2522type%2522%253A%2522template%2522%252C%2522payload%2522%253A%257B%2522template_type%2522%253A%2522generic%2522%252C%2522elements%2522%253A%255B%257B%2522title%2522%253A%2522test%2522%252C%2522subtitle%2522%253A%2522test+test%2522%252C%2522item_url%2522%253A%2522%2522%252C%2522image_url%2522%253A%2522https%253A%2F%2Fdata.fideinc.com%2Fcustom%2Fent_19286B%2Fid_1ABEA3C_image.png%2522%252C%2522buttons%2522%253A%255B%257B%2522type%2522%253A%2522element_share%2522%257D%252C%257B%2522type%2522%253A%2522postback%2522%252C%2522title%2522%253A%2522%5Cud83e%5Cudd11+%5Cu0410%5Cu043a%5Cu0446%5Cu0438%5Cu0438+%5Cu0432+%5Cu0437%5Cu0430%5Cu0432%5Cu0435%5Cu0434%5Cu0435%5Cu043d%5Cu0438%5Cu0438%2522%252C%2522payload%2522%253A%2522offers%2522%257D%255D%257D%255D%252C%2522image_aspect_ratio%2522%253A%2522horizontal%2522%257D%257D%257D%252C%2522tag%2522%253Anull%257D"
And so on
P.S. I can't use any external Facebook SDK in my project, I just need to get this request right
In case someone has the same problem, the answer is incredibly simple: use http_build_query instead of json_encode...
Related
I'm trying to replicate a post request done normally by a website form via postman but the server returns 500 error.
the form website URL that I'm dealing with is here.
what I have done so far is investigate the network request using chrome or safari dev tools, copy the request as cURL, import the cURL in postman and do the request.
what can be the possible reasons for the failure and what are the alternative ways to achieve the same result?
Postman Headers:
Most probably you must have used invalid request body. The browser shows parsed json body and you might have copied incomple request body.
To get full body click view source and copy the full content.
https://www.absolute.com/-/media/Commercial/resources/api/abt-api-working-with-absolute.pdf?la=en
I am trying to make the canonical request part for this one. On page 6 there is this part: Encoded hash of payload: Hash the entire body, HexEncode, and apply lowercase . I am not sure what is the payload that I should work on here if I'm trying to do a GET request. Is it the GET/POST params, or is it something else?
Payload is some data you send on the body of POST requests.
You can see more information on the docs.
With Postman examples you can see some requests, and notice POST is the only one which has body.
I know I'm late, #Felipe is slightly wrong here. Mistook what OP meant by payload. Generally payload does mean Body, but with Absolutes REST API, you send the payload in the Authorization header. It is a standard. And there is way better documentation available in AWS than Absolute.
Absolute also have C# SDKs.
AbsoluteSDK
AWS Signature Version 4 Docs or Signing a Request
Neo4j API url is: http://localhost:7474/db/data
When I use Chrome visiting this url, which is a GET request. This is the response I got
But when I use the restful client such as POSTMAN to make a g request.
This is the response I got.
My questions are
Both are GET request to the same url. Why Chrome browsing get a html page in return but Postman Request get JSON Response in return.
How Neo4j does that?
Is Neo4j using user agent detection, and if it is a browser visiting, it will give HTML page as response. And if it is a rest client request, it will give json response?
Thanks!
They use media type negotiation header. For example when requesting this site my browser sends a header like that:
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
As you can see it accepts primarily html, if that's not available then xhtml, then pure xml, and if that's not available - it accepts whatever the server can throw at it. Neo4j's website tries to serve content in that order. Postman likely just specifies application/json, or nothing at all (the application determines the default media type then), hence the response.
I'm building REST API, and when resource is created normally I return HTTP 201 Created along with Location header to specify where that resource is located. But from some reason http client is not redirecting.
I'm using Postman for this. Does anyone have idea on this problem?
In short, a Location header is not sufficient to trigger a client redirect. It must be used in conjunction with a 3xx HTTP status code.
References:
https://en.m.wikipedia.org/wiki/HTTP_location
Redirecting with a 201 created
This is one of those things where the expectation does not meet what actually happens, and the first thing people think is "well that doesn't work properly", as has been suggested in other comments.
The Location is just a random header, and clients, such as Postman or curl or anything else need to be instructed to follow them. Most won't do this by default, as that is an unreasonable default.
YouTube for example returns a body for some responses and a Location tag too. One example would be video uploads. They respond to your original meta-data for the video is sent with a POST, and they shove a Location URL which is the endpoint to upload the video too. If clients just randomly redirected to that you'd be having a bad time.
You can use Paw to make a "sequence", which I believe will let you take values from headers to reuse. This is also possible with Runscope Ghostinspector.
Im trying to get TripIt OAuth authentication working, but I find the documentation to go a bit over my head. TripIt docs
The paragraph below is from the documentation, I have tried putting together a POST request for a SOAP service where the documentation specified what to put into the headers and how to build an xml for the Http body. In this case I have no idea on how to build my request.
I have all the values the service asks for, just no idea of how to set these using only the info given below?
To obtain an authorized access token,
POST the following request parameters
to the URL:
https://api.tripit.com/oauth/access_token
oauth_consumer_key: The Consumer's public key.
oauth_nonce: A nonce no more than 80 characters in length.
oauth_signature: The signature of the reque…
oauth_signature_method: Current supported methods are HMAC-SHA1.
oauth_timestamp: The timestamp in seconds since the epoch.
oauth_token: The request token obtained in Step 1.
oauth_token_secret: The request token secret obtained in Step 1.
oauth_version: OPTIONAL - Assumed to be '1.0'
Could someone help me with how I'll go about building the POST request from the above?
Thank you:)
The way to do it yourself would be to read up on how the body of a POST request is put together (it looks a lot like a URL query string), build the string out of the various parts, and then use the request's -setHTTPBody: method.
Most people recommend using ASIHTTPRequest, which, among many other things, will do that work for you. See, in particular, the ASIFormDataRequest class, and its -setPostValue:forKey: method.
Here's some more detail on the format of the POST body:
From the W3C HTML4 spec, the section on forms.
The Wikipedia entry on "percent escaping".
From the HTML5 spec draft. These rules should be backwards-compatible, while being more precise than the text in the HTML4 spec, but no promises.