galen / PHP-Instagram-API

PHP 5.3+ wrapper for the Instagram API
338 stars 159 forks source link

ApiException thrown when calling getTag('äää') with parameter including unicode chars #45

Closed juuga closed 9 years ago

juuga commented 9 years ago

When I call

$instagram = new Instagram;
$instagram->setAccessToken('xxx');
$tag = $instagram->getTag('MyTäg');
$media = $tag->getMedia([]);

an Instagram\Core\ApiException is thrown with message 'Unknown Error'. When I remove the 'ä', it works fine. I have tried utf8_decode and iconv, but they have not helped.

The special characters get converted to something like MyT\xC3\xA4g which, of course, does not work in the URL https://api.instagram.com/v1/tags/<TAG>/media/recent

juuga commented 9 years ago

I believe the tag should be escaped with curl_escape for it to correctly become MyT%C3%A4g instead of MyT\xC3\xA4g

juuga commented 9 years ago

I figured it out. The tag should be passed to urlencode(). The problem is that $instagram->getTag() return the tag once again without the encoding. Here is a work around:

$tag = $instagram->getTag( urlencode('MyTäg') );

// reset tag to escaped version
$tagData = $tag->getData();
$tagData->name = urlencode($tagData->name);
$tag->setData($tagData);

$media = $tag->getMedia();

Hope this helps someone. I will see if I have time to make a pull request at some point...