php 使用 Graph Api 发送 Facebook 应用请求/邀请
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7368002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send Facebook App Request/Invite using Graph Api
提问by ivias
I have the following code that would get ur friends list using graph api
我有以下代码可以使用图形 api 获取您的朋友列表
function getFriendsList(){
$response = $this->api('/me/friends');
return $response;
}
This returns friends id and name. using graph api
这将返回朋友 ID 和姓名。使用图形 API
I then execute this code in my joomla module:
然后我在我的 joomla 模块中执行此代码:
$fbClient = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $fbClient->getUserId(TRUE);
//If FB User
if($fbUserId){
$f_list = $fbClient->getFriendsList();
after i get the array i display the firends picture
在我得到数组后,我显示了朋友的图片
foreach ($f_list as $friend) {
for($i = 0; $i < count($friend); $i++)
{
echo '<img src="http://graph.facebook.com/'.$friend[$i]['id'].'/picture"><br/>';
}
}
}
This would create the profile photos of my friends.
这将创建我朋友的个人资料照片。
My question is how do i create an onlick even so that when i click the photo i can send an individual facebook app request. ???
我的问题是我如何创建一个 onlick 以便当我点击照片时我可以发送一个单独的 Facebook 应用程序请求。???
回答by bkaid
Sending Facebook app requests are not available via the graph api. You can use the app requests javascript dialogto send the request though, you would just need to specify the user's id in the "to" property as detailed in the documentation.
无法通过图形 API 发送 Facebook 应用请求。您可以使用应用程序请求 javascript 对话框来发送请求,您只需要在文档中详细说明的“to”属性中指定用户的 ID。
Sample function:
示例功能:
<script>
FB.init({ appId: '**appId**', status: true, cookie: true, xfbml : true });
function sendRequest(to) {
FB.ui({method: 'apprequests', to: to, message: 'You should learn more about this awesome site.', data: 'tracking information for the user'});
return false;
}
</script>
Then just wire an onclick for each image to something like onclick="return sendRequest('**friendId**');"
然后只需将每个图像的 onclick 连接到类似的东西 onclick="return sendRequest('**friendId**');"
回答by Somnath Muluk
I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.
我有同样的问题。虽然回答问题很晚,但它会帮助某人。这就是为什么要回答这个问题。
Instead you can call this function in javascript: it will give you all friends with photos. Also group of friends who are currently using same app. You can send request to any of them.
相反,您可以在 javascript 中调用此函数:它将为您所有朋友提供照片。还有一群目前正在使用同一个应用程序的朋友。您可以向其中任何一个发送请求。
function sendRequestViaMultiFriendSelector() {
FB.ui({
method: 'apprequests',
message: "You should learn more about this awesome site."
});
}