Sunday, 15 July 2012

php - JSON - Importing Data Using FileGetContents not showing? -



php - JSON - Importing Data Using FileGetContents not showing? -

i've been writing little script monthly views user. when i've got access token of user , var_dump file_get_contents($url) correct-json, looks this.

$views = file_get_contents('https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3d%3dmine&start-date=2014-09-29&end-date=2014-10-29&metrics=views&access_token='.$responseobj->access_token); var_dump($views);

the result being:

{ "kind": "youtubeanalytics#resulttable", "columnheaders": [ { "name": string, "datatype": string, "columntype": string }, ], "rows": [ [ 2204 ] ] }

i'm unsure how utilize json import number "2204" , echo out. i'm trying:

$monthlyviews = $views['rows'][0]; var_dump($monthlyviews)

but isn't working , i'm not sure why. i'm getting nil responded except error saying:

fatal error: cannot utilize string offset array in /home/a1059253/public_html/oauth/callback.php on line 39

first, need parse json object:

$json = json_decode($views);

php parses json object, not array, code should this:

$monthlyviews = $json->rows[0][0]; echo $monthlyviews;

php json youtube-api

No comments:

Post a Comment