通过图形API创建和邀请组到事件(Creating and inviting a group to an event via graph api)

编程入门 行业动态 更新时间:2024-10-28 03:31:42
通过图形API创建和邀请组到事件(Creating and inviting a group to an event via graph api)

是否仍无法邀请所有小组成员参加小组活动? 我可以通过api创建群组活动,但不会邀请成员参加新活动。 如果我通过Facebook网站创建活动,我可以选择“邀请所有群组成员”。 我似乎找不到任何方法通过api重现该功能。

Is there still no way to invite all the group members to an group event? I am able to create the group event via the api, but members are not invited to the new event. If i create the event via the facebook website i have the option to select "invite all group members". I can't seem to find any way to reproduce that functionality via the api.

最满意答案

由于没有办法直接通过图形api做到这一点,我最终制作了我自己的php w / mysql解决方案。 基本上我会列出我所有小组成员的表格,然后检查他们是否被邀请参加我所有小组的活动。 这种强制方法的好处是,如果在创建事件后新成员加入,他们将被邀请参加所有未来事件。

facebook不告诉你每个时间段你可以从api邀请多少成员而不会被标记为垃圾邮件

转储组成员的代码:

function UpdateFacebookMemberDB($verbatim = FALSE) { global $access_token, $groupID; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/members?access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decoded = json_decode($return, true); $decoded = $decoded['data']; Sql_Connect(); if(!Sql_Query("DELETE FROM `Facebook_User`;")) { echo "Could not empty the `Facebook_User` table.<br>\n"; return FALSE; } foreach ($decoded as $value) { $query="INSERT INTO `Facebook_User` (`Name`, `FID`) VALUES ('".Sql_CleanInput($value['name'])."', '".Sql_CleanInput($value['id'])."');"; if(Sql_Query($query)) { if($verbatim) echo $value['name']." was added to the database.<br>"; } else if($verbatim) echo $value['name']." was <b>NOT</b> added to the database.<br>"; } if(!Sql_Query("DELETE FROM `Facebook_Event`;")) { echo "Could not empty the `Facebook_Event` table.<br>\n"; return FALSE; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decoded = json_decode($return, true); $decoded = $decoded['data']; foreach ($decoded as $value) { $eid = $value['id']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eid.'/invited?access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decod = json_decode($return, true); $decod = $decod['data']; foreach ($decod as $val) { $query="INSERT INTO `Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eid."', '".$val['id']."');"; if(Sql_Query($query)) { if($verbatim) echo $val['name']." was added to the database.<br>"; } else if($verbatim) echo $val['name']." was <b>NOT</b> added to the database.<br>"; } } Sql_Disconnect(); }

检查/邀请成员的代码:

function InviteClubToEvent) { global $access_token, $groupID; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decoded = json_decode($return, true); $decoded = $decoded['data']; $invite=0; for($x=count($decoded)-1;$x>=0;$x--) { $eventid = $decoded[$x]['id']; Sql_Connect(); $query="SELECT * from `Facebook_User` ORDER BY `FID` ASC;"; $qresult=Sql_Query($query); $data = array( 'access_token' => $access_token); $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); for($i=0;$i<Sql_Num_Rows($qresult);$i++) { $subquery="SELECT * from Facebook_Event WHERE `UserID` ='".Sql_Result($qresult,$i,"FID")."' AND `EventID` ='".$eventid."'LIMIT 1;"; if(Sql_Num_Rows(Sql_Query($subquery))==0) { $invite++; curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eventid.'/invited/'.Sql_Result($qresult,$i,"FID")); $return = curl_exec($ch); if($return == "true") { echo "$invite) ".Sql_Result($qresult,$i,"Name") . " has been invited to $eventid!<br>"; Sql_Query("INSERT INTO `sdbmwcca_main`.`Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eventid."', '".Sql_Result($qresult,$i,"FID")."');"); } else { echo "<hr><b>$invite) ".Sql_Result($qresult,$i,"Name") . " was not invited because: " . $return . "</b><hr>"; curl_close($ch); Sql_Disconnect(); die(); } } if($invite > ##some spam limit##) { $x = 0; break; } } curl_close ($ch); Sql_Disconnect(); } }

Since there was no way to do this directly via the graph api i ended up making my own php w/mysql solution. Basically i make a table of all my group's members, then i check if they have been invited to all my group's events. the good thing about this forced method is that if a new members joins after an event is created they will be invited to all future events.

facebook does not tell you how many members you can invite from the api per time period and not get flagged for spam

code to dump group members:

function UpdateFacebookMemberDB($verbatim = FALSE) { global $access_token, $groupID; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/members?access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decoded = json_decode($return, true); $decoded = $decoded['data']; Sql_Connect(); if(!Sql_Query("DELETE FROM `Facebook_User`;")) { echo "Could not empty the `Facebook_User` table.<br>\n"; return FALSE; } foreach ($decoded as $value) { $query="INSERT INTO `Facebook_User` (`Name`, `FID`) VALUES ('".Sql_CleanInput($value['name'])."', '".Sql_CleanInput($value['id'])."');"; if(Sql_Query($query)) { if($verbatim) echo $value['name']." was added to the database.<br>"; } else if($verbatim) echo $value['name']." was <b>NOT</b> added to the database.<br>"; } if(!Sql_Query("DELETE FROM `Facebook_Event`;")) { echo "Could not empty the `Facebook_Event` table.<br>\n"; return FALSE; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decoded = json_decode($return, true); $decoded = $decoded['data']; foreach ($decoded as $value) { $eid = $value['id']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eid.'/invited?access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decod = json_decode($return, true); $decod = $decod['data']; foreach ($decod as $val) { $query="INSERT INTO `Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eid."', '".$val['id']."');"; if(Sql_Query($query)) { if($verbatim) echo $val['name']." was added to the database.<br>"; } else if($verbatim) echo $val['name']." was <b>NOT</b> added to the database.<br>"; } } Sql_Disconnect(); }

code to check/invite members:

function InviteClubToEvent) { global $access_token, $groupID; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$groupID.'/events?fields=start_time&since=now&access_token='.$access_token); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return = curl_exec($ch); curl_close ($ch); $decoded = json_decode($return, true); $decoded = $decoded['data']; $invite=0; for($x=count($decoded)-1;$x>=0;$x--) { $eventid = $decoded[$x]['id']; Sql_Connect(); $query="SELECT * from `Facebook_User` ORDER BY `FID` ASC;"; $qresult=Sql_Query($query); $data = array( 'access_token' => $access_token); $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_USERAGENT , 'facebook-php-3.2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); for($i=0;$i<Sql_Num_Rows($qresult);$i++) { $subquery="SELECT * from Facebook_Event WHERE `UserID` ='".Sql_Result($qresult,$i,"FID")."' AND `EventID` ='".$eventid."'LIMIT 1;"; if(Sql_Num_Rows(Sql_Query($subquery))==0) { $invite++; curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$eventid.'/invited/'.Sql_Result($qresult,$i,"FID")); $return = curl_exec($ch); if($return == "true") { echo "$invite) ".Sql_Result($qresult,$i,"Name") . " has been invited to $eventid!<br>"; Sql_Query("INSERT INTO `sdbmwcca_main`.`Facebook_Event` (`EventID`, `UserID`) VALUES ('".$eventid."', '".Sql_Result($qresult,$i,"FID")."');"); } else { echo "<hr><b>$invite) ".Sql_Result($qresult,$i,"Name") . " was not invited because: " . $return . "</b><hr>"; curl_close($ch); Sql_Disconnect(); die(); } } if($invite > ##some spam limit##) { $x = 0; break; } } curl_close ($ch); Sql_Disconnect(); } }

更多推荐

本文发布于:2023-08-04 15:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417456.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图形   事件   Creating   inviting   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!