简体   繁体   English

使用PHP从REST Blogger Api请求中检索JSON对象

[英]Retrieve JSON Object from REST Blogger Api Request with PHP

I'm still wondering how to get json object from REST Api request from this link https://developers.google.com/blogger/docs/3.0/using . 我仍然想知道如何通过此链接https://developers.google.com/blogger/docs/3.0/using从REST Api请求中获取json对象。

It says GET https://www.googleapis.com/blogger/v3/blogs/2399953?key=YOUR-API-KEY request will give informations about particular blog. 它说GET https://www.googleapis.com/blogger/v3/blogs/2399953?key=YOUR-API-KEY请求将提供有关特定博客的信息。

I'm also PHP noobs. 我也是PHP新手。 Here's my code. 这是我的代码。

<?php
$blogID = 'xxx'; 
$apikey = 'yyy';

$requestURL = "https://www.googleapis.com/blogger/v3/blogs/{$blogID}?key={$apikey}";

$json = file_get_contents($requestURL);
print_r($json);

?>

I have no idea about this, so please help me to find where the problem is. 我对此一无所知,因此请帮助我找出问题所在。 Thanks in advance 提前致谢

Try this: 尝试这个:

$json = json_decode(file_get_contents($requestURL));

You are fetching a JSON string and trying to print_r it, which only works on arrays. 您正在获取JSON字符串并尝试对其进行print_r处理,该方法仅适用于数组。

json_decode , as its name implies, decodes the JSON string and transforms it into an array / object. json_decodejson_decode解码JSON字符串并将其转换为数组/对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM