使用PHP从Google Plus API获取用户信息


Get user info information from Google Plus API with PHP

当您访问此页面时:

https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=AIzaSyAwnz3yjIcvsosfbudkzl9oogGrT21m6Ns

我想什么是所谓的对象,出现了很多信息。但当我尝试做一个简单的GET调用,然后打印它时,就像这样:

$tweets = $_GET['https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=AIzaSyAwnz3yjIcvsosfbudkzl9oogGrT21m6Ns'];
print_r($tweets);

它什么也不回。。。为什么?

$_GET超级全局由当前请求的查询字符串填充,它不用于从interwebs中获取内容。

您正在寻找file_get_contents():

$url = 'https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=AIzaSyAwnz3yjIcvsosfbudkzl9oogGrT21m6Ns';
$tweets = file_get_contents($url);
print_r($tweets);

如果其中包含JSON编码的响应,则需要额外使用json_decode()来使用它。

您知道如何使用$_GET吗?查看PHP文档,您一定犯了一个错误,或者您使用它的方式不对。