API request works from local machine, not server

I have an interesting situation when calling the Shopify API. I am using a standard procedure to call a url and get data like:

define('SHOPIFY_SHOP', 'myteststore.myshopify.com');
define('SHOPIFY_APP_API_KEY', 'xxxx');
define('SHOPIFY_APP_PASSWORD', 'yyy');
$shop_url = 'https://'.SHOPIFY_APP_API_KEY.':'.SHOPIFY_APP_PASSWORD.'@'.SHOPIFY_SHOP;
$response = Requests::get($shop_url.'/admin/products.json');

      

And I get the answer correctly, parse the data and everything works fine. Now when I put it on an actual server (Ubuntu 12.04) I noticed a strange message from the Spotify API:

[API] Invalid API key or access token (unrecognized login or wrong password)

      

I tried to create a new application, but it is still the same. So the same file and the same set works on my machine, but not on the server. (the only difference in the file is the path to the requests library, require_once './Requests/library/Requests.php';

for Linux and require_once '..\Requests\library\Requests.php';

Windows). As stated, I'm using requests , and I'm guessing there must be some trick where the library (or whatever) overwrites the URl and it doesn't get to Shopify correctly.

I tried using CURL with url directly and it works exactly like this. Can anyone point me to what might be causing this?

Update: I switched to a different library which solved the problem, but would like to know what caused this as I had a lot of experience with it Requests

up to this point.

+3


source to share


2 answers


I couldn't figure out why this is happening, it seems like the library is Requests

stripping parameters from GET

requests, so I went to the library unirest

and that solved the problem.



+1


source


I am starting to use the same lib and I came across something important right after finding this question: https://github.com/rmccue/Requests/issues/142#issuecomment-147276906

Quoting the relevant part:



This is an intentional part of the API design; in a typical use case, you don't necessarily need the data sent with the request. Building the URL is just a convenience for you.

Requests :: get is a helper function designed to make GET requests light in code, so there is no $ data parameter there. If you need to send data, use the request "Requests :: request"

$response = Requests::request( 'http://httpbin.org/get', $headers, $data, Requests::GET, $options );
// GET is the default for type, and $options can be blank, so this can be shortened:
$response = Requests::request( 'http://httpbin.org/get', $headers, $data );

      

+2


source







All Articles