Facebook图表api检查用户是否是使用PHP的组的成员 [英] facebook graph api check if user is a member of a group using PHP

查看:104
本文介绍了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

这篇关于Facebook图表api检查用户是否是使用PHP的组的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆