ricbra / php-discogs-api

PHP 5.4 Implementation of the Discogs API
MIT License
152 stars 96 forks source link

I added the getImage operation, couln't make a working Guzzle model for receiving binary image data #20

Closed eticdev closed 10 years ago

eticdev commented 10 years ago

Part of service.php

An attempt to describe the getImage operation for Discogs and the response model (based on Discogs API: Images).

It requires an OAuth token (tested after successful authentification).

// ...
,
        'getImage' => [
            'httpMethod' => 'GET',
            'uri' => 'images/{filename}',
            'responseModel' => 'GetImage',
            'parameters' => [
                'filename' => [
                    'type' => 'string',
                    'location' => 'uri',
                    'required' => true
                ]
            ]
        ]
    ],
    'models' => [
        'GetResponse' => [
            'type' => 'object',
            'additionalProperties' => [
                'location' => 'json'
            ],
        ],
        'GetImage' => [
            'type' => 'object',
            'additionalProperties' => [
                'location' => 'body'
            ],
        ]
    ]
];
eticdev commented 10 years ago

I thought the result will be located in the body, but it is always empty... or I don't know how to correctly get it.

I was still able to verify the image was really there by checking the *GuzzleHttp\Message\AbstractMessage*headers of the $response (content-type and content-length) while debugging the guzzle-services visit function (in ProcessResponse.php, line #96).

ricbra commented 10 years ago

Hi @eticdev I'm quite busy at the moment. I did take a quick look at your issue but I have to take a deeper look before I can say anything usefull. Perhaps you could also try getting some help on the Guzzle (this library is basically an implementation of Guzzle) mailinglist or Gitter.

ghost commented 10 years ago

Hi,

Same problem. I need a function that allow get image. Discogs return the "You must authenticate to access this resource." error. I wait for a solutions.

ricbra commented 10 years ago

@eticdev I released a new version with a fix.

@JonathanBesomi you should send a signed OAuth request as stated in the docs.

eticdev commented 10 years ago

Great @ricbra, thank you so much!!!

eticdev commented 10 years ago

Just to let you know that I was able to retrieve the image using $response['image']->getContents(), so everything is working perfectly, thanks again @ricbra !!!