I have a site where I fetch reddit comments using Guzzle and Reddits json api. While it tends to be really slow, it works, but I've run into an issue when trying to load more children via the /api/morechildren.json endpoint.
I always receive a 403 forbidden error when trying to get more children. These are the params I am using including the data and the endpoint which I am hitting.
array(2) {
["request"]=>
string(44) "https://www.reddit.com/api/morechildren.json"
["data"]=>
array(6) {
["link_id"]=>
string(10) "t3_cz36xw7"
["id"]=>
string(10) "t1_cz361ai"
["depth"]=>
string(1) "1"
["children"]=>
string(7) "cz36xw7"
["sort"]=>
string(10) "confidence"
["api_type"]=>
string(4) "json"
}
}
You can see the api I'm trying to hit here: https://www.reddit.com/dev/api/oauth#GET_api_morechildren
No matter what I try, i get 'string(116) "Client error response [url] https://www.reddit.com/api/morechildren.json [status code] 403 [reason phrase] Forbidden"'
Any ideas?
Authentication is needed. OAuth is authorisation library but hard to use without 3rd party library. Look at https://github.com/OAuthSwift/OAuthSwift, it's a good authorisation library and easy to use.
Related
I'm working on a cURL script to communicate with an API. I wrote a script to retrieve the data with a cURL request and the data is displaying as follows. This is just one chunk of the JSON response as there are usually multiple users online. The unique identifier is ["fromAddress"]=> string(18) "127.0.0.1:5060" which is constant no matter what. The CALLID field is unique every time a call is initiated from the server which makes it a real pain!
What I need to with the JSON Response is this:
Get [CALLID] from array# where ["fromAddress"] equals"127.0.0.1:5060"
Save to a php variable.
I'm not sure what the next step is. Can someone please point me in the right direction?
Thanks!
array(35) { ["callID"]=> string(22) "U1A7B9F7T61A2BC05S2eI1" ["callType"]=> string(3) "sip" ["participantID"]=> int(2) ["started"]=> int(15551212) ["updated"]=> int(15551212) ["name"]=> string(9) "TEST CALL" ["notes"]=> string(0) "" ["toNumber"]=> string(12) "+15551313" ["fromUri"]=> string(58) "sip:5551212#127.0.0.1:5060;pstn-params=908481808882" ["fromAddress"]=> string(18) "127.0.0.1:5060" ["fromName"]=> string(15) "WIRELESS CALLER" ["fromNumber"]=> string(12) "+15551212" ["location"]=> string(14) "SOMEWHERE, CO, US"
you posted a result from var_dump and is not complete
usually when receive json from a response you need to convert it to php's object using json_decode since response always return a string instead an object.
$obj= json_decode($response)
then you can access the data like thia
$obj['callID']
$obj['fromAddress']
I have a CRM set to crm.example.com And a active store on example.com (on the same server)
Both running with NGINX.
Im trying to request the whole categories list (43 categories) but i'm getting only 10. (The default value set by WooCommerce).
I tried using the per_page parameter but it seems like the server is ignore the GET.
I checked the request sent from crm.example.com and got that:
object(Automattic\WooCommerce\HttpClient\Request)#85 (5) {
["url":"Automattic\WooCommerce\HttpClient\Request":private]=>
string(67) "https://example.com/wp-json/wc/v2/products/categories/?per_page=100"
["method":"Automattic\WooCommerce\HttpClient\Request":private]=>
string(3) "GET"
["parameters":"Automattic\WooCommerce\HttpClient\Request":private]=>
array(1) {
["per_page"]=>
int(100)
}
["headers":"Automattic\WooCommerce\HttpClient\Request":private]=>
array(2) {
["Accept"]=>
string(16) "application/json"
["User-Agent"]=>
string(32) "WooCommerce API Client-PHP/1.3.0"
}
["body":"Automattic\WooCommerce\HttpClient\Request":private]=>
string(0) ""
}
But yet there is only 10 results.
i'm thinking maybe the NGINX server is ignoring the GET parameters as a security policy?
Folks I think I may miss a dead simple thing but I just have no idea where to look for it.
So I'm trying to implement block.io API to accept bitcoin payments on a website built on PHP. Now the Docs say that all notification events will use JSON objects pushed to my server through POST requests. So I decided to make a test BTC payment and log all requests on a specified URL to my DB. And here what I gen on dumping getallheaders()
{
["Content-Type"]=>
string(16) "application/json"
["User-Agent"]=>
string(12) "Block.io/0.1"
["Accept"]=>
string(10) "text/plain"
["Authorization"]=>
string(10) "Basic Og=="
["Connection"]=>
string(5) "close"
["Host"]=>
string(17) "site.com"
["Content-Length"]=>
string(3) "462" }
But dumping $_POST gives me an empty array. Dumping $_SERVER and $_GET gives nothing useful either.
So my question is how can I find the JSON string declared in Content-Type?
Any suggestion would be helpful!
Thanks!
Because the Content-Type is application/json (not application/x-www-form-urlencoded)
$inputJSON = file_get_contents('php://input');
EDIT: excellent explanation at PHP "php://input" vs $_POST
I am sending POST data to a php page and receiving it by var_dump($_POST). However the $_POST is always empty and the $_GET contains the values. I'm certain its a POST request and have tested in Postman REST client and cURL. I am using PHP 5.5.3 and Apache 2.2.
Thanks
EDIT:
I'm using the php scripts as an api so currently I am testing using the above mentioned tools to test the request using POST.
For example I am using this cURL request curl -X POST http://dev/project/build/api/registrants.php?hello=there
Contents of my $_SERVER (redacted in areas)
array(25) {
["HTTP_USER_AGENT"]=>
string(11) "curl/7.37.1"
["HTTP_HOST"]=>
string(3) "dev"
["HTTP_ACCEPT"]=>
string(3) "*/*"
["PATH"]=>
string(29) "/usr/bin:/bin:/usr/sbin:/sbin"
["SERVER_SIGNATURE"]=>
string(0) ""
["SERVER_SOFTWARE"]=>
string(67) "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8za DAV/2 PHP/5.5.3"
["SERVER_NAME"]=>
string(3) "dev"
["SERVER_ADDR"]=>
string(9) "127.0.0.1"
["SERVER_PORT"]=>
string(2) "80"
["REMOTE_ADDR"]=>
string(9) "127.0.0.1"
["DOCUMENT_ROOT"]=>
string(25) "/Applications/MAMP/htdocs"
["SERVER_ADMIN"]=>
string(15) "you#example.com"
["SCRIPT_FILENAME"]=>
string(59) "/Applications/MAMP/htdocs/project/build/api/registrants.php"
["REMOTE_PORT"]=>
string(5) "51096"
["GATEWAY_INTERFACE"]=>
string(7) "CGI/1.1"
["SERVER_PROTOCOL"]=>
string(8) "HTTP/1.1"
["REQUEST_METHOD"]=>
string(4) "POST"
["QUERY_STRING"]=>
string(10) "hello=there"
["REQUEST_URI"]=>
string(45) "/project/build/api/registrants.php?hello=there"
["SCRIPT_NAME"]=>
string(34) "/project/build/api/registrants.php"
["PHP_SELF"]=>
string(34) "/project/build/api/registrants.php"
["REQUEST_TIME_FLOAT"]=>
float(1416256385.03)
["REQUEST_TIME"]=>
int(1416256385)
["argv"]=>
array(1) {
[0]=>
string(10) "hello=there"
}
["argc"]=>
int(1)
}
In your <form> tag, make sure the method="POST" attribute is present.
Well, I was having the same problem and I discovered that the error was that I was using the wrong headers and the variables should be passed in the body of the request and not as URL parameters. I was using Postman to generate POST requests and I was getting $_GET filled and $_POST as (array(0)), so I read about $_POST superglobal and and it only gets filled when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request, according to PHP documentation here: http://php.net/manual/en/reserved.variables.post.php. Then, I read the Postman manual and it shows at the print screens that the parameters must be at the body as explained here at the session request body: https://www.getpostman.com/docs/v6/postman/sending_api_requests/requests. As said by steve on his comment on your question, using curl this request should be formatted like this:
curl -X POST --data "param1=value1¶m2=value2" https://example.com/resource.cgi
I am trying to configure ArrestDB to create an api for my site.
https://github.com/alixaxel/ArrestDB
As it says in the installation I need to change the $dsn to:
MySQL:
$dsn = 'mysql://[user[:pass]#]host[:port]/db/;
Currently I have
$dsn = 'mysql://user:password#localhost/database/';
I tried it with the brackets above, but that lead to a 503 service unavailable error. When I remove the brackets, it leads to this error:
{
"error": {
"code": 400,
"status": "Bad Request"
}
}
Do you have any idea what I am doing wrong? Everything looks correct to me
Edit:
Tried advice below and the api returned:
array(28) {
["REDIRECT_STATUS"]=> string(3) "200"
["HTTP_HOST"]=> string(16) "api.shopsavr.com"
["HTTP_CONNECTION"]=> string(10) "keep-alive"
["HTTP_ACCEPT"]=> string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
["HTTP_USER_AGENT"]=> string(109) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36"
["HTTP_ACCEPT_ENCODING"]=> string(17) "gzip,deflate,sdch"
["HTTP_ACCEPT_LANGUAGE"]=> string(14) "en-US,en;q=0.8"
["PATH"]=> string(209) "/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin"
["SERVER_SIGNATURE"]=> string(0) ""
["SERVER_SOFTWARE"]=> string(136) "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.4.20"
["SERVER_NAME"]=> string(16) "api.shopsavr.com"
["SERVER_ADDR"]=> string(11) "50.28.7.250"
["SERVER_PORT"]=> string(2) "80"
["REMOTE_ADDR"]=> string(12) "67.247.5.220"
["DOCUMENT_ROOT"]=> string(30) "/home/shopsavr/public_html/api"
["SERVER_ADMIN"]=> string(26) "webmaster#api.shopsavr.com"
["SCRIPT_FILENAME"]=> string(40) "/home/shopsavr/public_html/api/index.php"
["REMOTE_PORT"]=> string(5) "58487"
["REDIRECT_URL"]=> string(8) "/PRODUCT"
["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1"
["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1"
["REQUEST_METHOD"]=> string(3) "GET"
["QUERY_STRING"]=> string(0) ""
["REQUEST_URI"]=> string(8) "/PRODUCT"
["SCRIPT_NAME"]=> string(10) "/index.php"
["PHP_SELF"]=> string(10) "/index.php"
["REQUEST_TIME_FLOAT"]=> float(1383666718.92)
["REQUEST_TIME"]=> int(1383666718)
}
http://localhost/ArrestDB/index.php/[table]
worked perfect for me
don't put bracket on dns
...still working out how to post....
Problem
According to your code and dump information ArrestDB is not receiving your full request. The contents of your $_SERVER['REQUEST_URI'] is "/" which means that something is likely wrong in your .htaccess files which should be capturing any address and directing it to the ArrestDB PHP file.
Background info
Normally HTTP response codes in the4XX range represent bad requests.
Normally HTTP response codes in the5XX range represent errors.
ArrestDB would respond with a 4XX error code (not 400 precisely but another 4XX error) if some other error would occur (bad SQL parameters, server timeout etc.).
ArrestDB would respond with a 5XX error code (503 in particular) if the database connection would be in any way "bad".
Reasoning
Because of the fact that it responds with precisely 400 as the error code it means that there is no "specific" error code it can supply (400 meaning "unknown type of bad connection").
Possible fix
First to confirm my theory I recommend you remove the var_dump + exit I asked you to put in and in stead write $_SERVER['REQUEST_URI'] = "/products";. This should force ArrestDB to think it needs to list the products table. After confirming everything works when we use this hack we'll attempt to fix your .htaccess problem.
If you don't have the .htaccess file you need to put the full URL to work, just like this: http://localhost/ArrestDB/index.php/[table]