Twitch api with PHP

1,078 views
Skip to first unread message

Brandon Stewart

unread,
Dec 3, 2013, 9:16:15 AM12/3/13
to twitc...@googlegroups.com
I have this code ( at the bottom of this document )  with php, and I was wondering what I broke? I get the following error when I try and access the page on my Localhost "Warning: file_get_contents() [<a href='function.file-get-contents'>function.file-get-contents</a>]: Unable to find the wrapper &quot;https&quot; - did you forget to enable it when you configured PHP? in C:\wamp\www\twitch.php on line 6" and " Warning: file_get_contents(https://api.twitch.tv/kraken/streams/branndons?client_id=ashdjksahdjksahdjashkd) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No error in C:\wamp\www\twitch.php on line 6"

Thanks,

<?php
 
$channelName = 'branndons';
 
$clientId = 'ashdjksahjkdhjshdjksa';  //not my real id... js 
 
if ($json_array['stream'] != NULL) {
    $channelTitle = $json_array['stream']['channel']['display_name'];
    $streamTitle = $json_array['stream']['channel']['status'];
    $currentGame = $json_array['stream']['channel']['game'];
 
    echo "$channelTitle is online playing $currentGame";
} else {
    echo "$channelName is offline";
}
 
?>


thanks :)

Anthony Diaz

unread,
Dec 3, 2013, 10:35:55 PM12/3/13
to twitc...@googlegroups.com
Your first error is linked to OpenSSL (or some other SSL manager) not being present to handle HTTPS.  If you have openSSL as a .dll, add this into your php.ini at the bottom after you stash the .ddl into your ./ext/ directory:
; make sure openSSL is loaded and allows for URL's to be used in file_get_contents
extension=php_openssl.dll
allow_url_include = On  

Your second error is likely related to the allow_url_fopen flag in your php.ini.  This will need to be set to on.

If you wish to use cURL as a method for getting the data, I have put together a library to handle all of the calls for you.  It is available here.
Reply all
Reply to author
Forward
0 new messages