unsplash / unsplash-php

👻 Official PHP wrapper for the Unsplash API
MIT License
415 stars 74 forks source link

The path of a URI with an authority must start with a slash "/" or be empty #46

Closed riza2359 closed 7 years ago

riza2359 commented 7 years ago

Hi, I got InvalidArgumentException in Uri.php line 693: The path of a URI with an authority must start with a slash "/" or be empty

This is my code:

        \Crew\Unsplash\HttpClient::init([
            'applicationId' => 'appId'
        ]);

        $photos = \Crew\Unsplash\Photo::all();

        var_dump($photos);

This is composer.json:

    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "crewlabs/unsplash": "^2.2",
        "guzzlehttp/guzzle": "^6.2"
    },

PHP -v: PHP 7.0.9 (cli) (built: Aug 26 2016 06:17:04) ( NTS )

And the error stack:

in Uri.php line 693
at Uri->validateState() in Uri.php line 471
at Uri->withHost('api.unsplash.com') in HttpClient.php line 140
at HttpClient->Crew\Unsplash\{closure}(object(Request)) in Middleware.php line 233
at Middleware::GuzzleHttp\{closure}(object(Request), array('synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Middleware.php line 233
at Middleware::GuzzleHttp\{closure}(object(Request), array('synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in HandlerStack.php line 67
at HandlerStack->__invoke(object(Request), array('synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Client.php line 275
at Client->transfer(object(Request), array('synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) in Client.php line 96
at Client->sendAsync(object(Request), array('query' => array('page' => '1', 'per_page' => '10'), 'synchronous' => true, 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, '_conditional' => array('User-Agent' => 'GuzzleHttp/6.2.1 curl/7.45.0 PHP/7.0.9'))) in Client.php line 104
at Client->send(object(Request), array('query' => array('page' => '1', 'per_page' => '10'), 'synchronous' => true)) in HttpClient.php line 111
at HttpClient->send('get', array('photos', array('query' => array('page' => '1', 'per_page' => '10')))) in Endpoint.php line 74
at Endpoint::__callStatic('get', array('photos', array('query' => array('page' => '1', 'per_page' => '10')))) in Photo.php line 32
at Photo::all() in UtilController.php line 23
at UtilController->getFreeImages(object(Request))

Is my implementation wrong?

dechuck commented 7 years ago

Hi @riza2359, I will take a closer look later in the day.

riza2359 commented 7 years ago

Hi @dechuck, sorry to bug you, did you manage to look at the issue?

dechuck commented 7 years ago

Hey @riza2359,

I wasn't able to reproduce the issue, on both php 5.6 and php 7.1 Do you have more information?

cc. @aaronklaassen

riza2359 commented 7 years ago

Hi, can help clarifying what other information I should provide?

I'm using Laravel and I'm trying to do this:

public function searchImages($query)
{
    \Crew\Unsplash\HttpClient::init([
        'applicationId' => 'appId'
    ]);

    $photos = \Crew\Unsplash\Photo::search($query);

    return $photos;
}

I don't pass the app secret because I only want to retrieve public photos. Currently I can get it work by bypassing the SDK with this code:

public function searchImages($query)
{
    $client = new GuzzleHttp\Client();
    $res = $client->get("https://api.unsplash.com/search/photos?query={$query}&client_id=appId");

    $data = json_decode($res->getBody()->getContents());
    $images = $data->results;
}

OS using macOS sierra.

Koshelenok commented 7 years ago

Hello.

I have the same issue. Exception in a Uri.php when calling static method "all" in class Photo. At the first params sending string "photos" and then

The path of a URI with an authority must start with a slash "/" or be empty.

tangod0wn commented 7 years ago

Same issue as well, to do with BLOB storage.

no fix yet - if I figure it out will post what I did.

krisnaw commented 7 years ago

Hi, I'm having the exact same issue on Laravel 5.4. Any updates about this?

aaronklaassen commented 7 years ago

Hey folks. Sorry for the delay here. I'll take a look asap.

treeleaf commented 7 years ago

It's caused by an update in guzzle client that a uri must start with a leading / or be empty. I have added it in a pull request.. https://github.com/unsplash/unsplash-php/pull/49/commits/590bb78551cc83c0f67465beb1df6f3073cfeb98

aaronklaassen commented 7 years ago

^ Fix is available in v2.3.0