Facebook图表api检查用户是否是使用PHP的组的成员

Facebook图表api检查用户是否是使用PHP的组的成员

问题描述:

我想检查用户是否是使用Facebook图形API的组的成员...

i want to check if a user is a member of a group using facebook graph api...

我有这个:

$group = file_get_contents("https://graph.facebook.com/177129325652421/members?access_token=XXXXXXXX");
$group = json_decode($group);

$checkuser = $group->data;

并使用他的 facebook id

and check the user if is a member by using his facebook id and in_array()

if(in_array($_GET["fid"],$checkuser)){

echo "yes";

} else {

echo "no";
}

有人可以帮我纠正这个...我的代码不工作...

can someone help me to correct this please... my code is not working...

参考: https://developers.facebook.com/docs/reference/api/

使用API​​网址:

https://graph.facebook.com/me/groups

获取用户的组。在上述链接中,将 me / 更改为用户的FB ID。您还必须通过访问令牌。

To get a user's groups. In the above link, change the me/ to the user's FB ID. You must also pass in an Access Token.

该回复将被JSON编码。使用 json_decode 到PHP关联数组。迭代它并检查您想要的组。

The reply will be JSON encoded. Decode it using json_decode to a PHP Associative array. Iterate over it and check for the group you want.

Graph API不会立即返回所有组。您必须在每个响应结束时使用分页链接来获取更多内容,或者使用 limit 参数来请求尽可能多的。

The Graph API does not return all groups at once. You must either use the pagination links at the end of each response to fetch more, or use the limit parameter to request as many as you need.

以下代码示例将发布您作为

The following code sample will post the IDs of the Groups you are a part of

<?php

$url = "https://graph.facebook.com/me/groups?access_token=AAAAAAITEghMBAMDc6iLFRSlVZCoWR0W3xVpEl1v7ZAxJRI3nh6X2GH0ZBDlrNMxupHXWfW5Tdy0jsrITfwnyfMhv2pNgXsVKkhHRoZC6dAZDZD";
$response = file_get_contents($url);

$obj = json_decode($response);

foreach($obj->data as $value) {
    echo $value->id;
    echo '<br>';
}

/* to check for existence of a particular group 

foreach($obj->data as $value) {
    if ($value->id == $yourID) {
        //found
        break;
    }

    //not found. fetch next page of groups
}

*/

PS - 如果运行上面的代码给你一个错误,说明找不到https的包装器,你需要取消注释/添加PHP扩展名 extension = php_openssl.dll

PS - If running the above code gives you an error stating Could not find wrapper for "https", you need to uncomment/add the PHP extension extension=php_openssl.dll