/    Sign up×
Community /Pin to ProfileBookmark

list user subscriptions to all youtube channels after getting access token

0 down vote favorite

I’m using Google Api to get a list of youtube channels the users subscribed to using this file [url]https://github.com/google/google-api-php-client/blob/master/examples/user-example.php[/url] and setting $client_id,$client_secret and $redirect_ur. The redirect url is another webpage that stores the code in a variable and it’s the same url in the google developer app settings. after running the page I get redirected to the url that looks like this

[url]http://mawk3y.net/google/test.php?code=code[/url] here
$code = $_REQUEST[‘code’];

Now I want to use the access token to get a list of youtube channel ids the user had subscribed to using this code

$data =file_get_contents(‘https://www.googleapis.com/youtube/v3/subscriptions?part=snippet
&maxResults=50&access_token=’.$code.’&mine=true&key=My API Key Here’);
echo $data;

But i get nothing at all. Is this a wrong way to fetch data or something else?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 29.2015 — Do you have all error reporting turned on? (Could simply be that your PHP configuration does not allow file_get_contents() to use URLs, a common security setting, in which case you'd need to user cURL instead.) Also, you might want to var_export($data) instead of echoing it, so that you at least know if it's false, null, or something else.
Copy linkTweet thisAlerts:
@phpWebDeveloperauthorJan 29.2015 — var_export($data) returned false
Copy linkTweet thisAlerts:
@NogDogJan 29.2015 — So we know that the file_get_contents() call failed. You might want to turn all all error reporting.
[code=php]
<?php
error_reporting(E_ALL);
ini_set('display_errors', true); // set to false for production mode

// rest of code...
[/code]
Copy linkTweet thisAlerts:
@phpWebDeveloperauthorJan 29.2015 — First of all thanks a lot for trying to help

Error:

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/iy0xods5/public_html/google/test.php on line 7

Warning: file_get_contents(https://www.googleapis .com/youtube/v3/subscriptions?part=snippet&maxResults=30&mine=true&access_token=ACCESS TOKEN HERE&key=API KEY HERE): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/iy0xods5/public_html/google/test.php on line 7
×

Success!

Help @phpWebDeveloper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...