【问题标题】:StackOverflow API and PHP CLI and JSONStackOverflow API 和 PHP CLI 和 JSON
【发布时间】:2011-12-21 15:44:55
【问题描述】:

我是 JSON 和 API 的新手,我想制作一个使用 StackOverflow API 的 PHP CLI 脚本。我给自己做了一把钥匙,这是我目前的代码:

<?php

//Call stack API .$key
$google_url = "http://api.stackoverflow.com/1.1/stats";

//Get and Store API results into a variable
$result = file_get_contents($google_url);
//$jsonArray = json_decode($result);
print_r($result);
//var_dump($jsonArray);

?>

但是 print_r($result); 返回一些奇怪的字符。看不懂,能不能给点资料?任何帮助将不胜感激。整个项目将是一个关于 StackOverflow 帖子和 cmets 的开源搜索引擎!

【问题讨论】:

  • 您可能正在获取 gzip 压缩形式的数据。如果您使用 cURL 而不是 file_get_contents(),您可以调整选项以便它为您处理 gzip。
  • 非常感谢这确实是问题

标签: php json api command-line-interface stackexchange-api


【解决方案1】:

即使你没有在http请求中发送accept:gzip标头,你也需要解压它,因为all responses are gzip'd

How can I read GZIP-ed response from Stackoverflow API in PHP?

【讨论】:

  • OOOO 你这个摇滚人,非常感谢!这可以解决我的问题!还有一个问题,所以我想问一个问题,它的 cmets 使用这个 API 如何获取它并将它们存储在一个数组中!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-17
  • 2015-07-01
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多