来自vb.net或PHP的Facebook通知?
有谁知道是否有可能通过Vb.Net或PHP使用Facebook SDK版本4创建Facebook通知。来自vb.net或PHP的Facebook通知?
理想情况下,我希望我的网站上的用户输入他们的Facebook登录信息,然后存储他们的[facebook id],这样我就可以通过VB.Net每周发送状态通知到他们的Facebook帐户。
编辑 到目前为止,我从JavaScript获取ID范围和测试其复制到PHP
<?php
$appId = '77585851581xxxx';
$appSecret = 'xxxx';
$userId = '1015273548332xxxx'; //Scope ID
$accesstoken = $appId . '|' . $appSecret;
$notificationText = 'The cake is a lie.';
//Get Access Token
$args = array('grant_type' => 'client_credentials',
'client_id' => $appId,
'client_secret' => $appSecret);
$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$returnValue = curl_exec($ch);
curl_close($ch);
echo $returnValue;
$accesstoken = $returnValue;
//Set Notification
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook');
$url = 'https://graph.facebook.com/' . $userId . '/notifications' .
'?access_token=' . $accesstoken .
'&template=' . $notificationText .
'&href=';
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
echo $curlResult;
?>
我现在得到的错误:
Sorry, something went wrong. We're working on getting this fixed as soon as we can.
教程为PHP SDK 4.0 :http://www.devils-heaven.com/facebook-php-sdk-4-0-tutorial/
虽然我会建议使用简单的CURL调用App Notificati ons,你不需要PHP SDK。示例代码可以在这里找到:http://blog.limesoda.com/2014/08/app-notifications-facebook-apps/
这篇文章是在德国,但代码的相关部分:
$accessToken = $appId . '|' . $appSecret;
$notificationText = 'The cake is a lie.';
//init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook');
//send notification
$url = 'https://graph.facebook.com/' . $userId . '/notifications' .
'?access_token=' . $accesstoken .
'&template=' . $notificationText .
'&href=';
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
感谢指针,我认为curl方法由于版本4而停止,无论如何都不愿意使用任何方法让我开始朝着正确的方向前进。我有一个快速的看,它没有工作,所以我猜我的FB应用程序设置有问题。今晚我会再看一次。谢谢你的帮助。 – widget 2014-09-12 12:31:56
为什么? curl是一个基本的php功能,与php sdk没有关系。而新的SDK也使用卷曲。 – luschn 2014-09-12 13:18:54
顺便说一句,当然用户必须先授权你的应用程序,然后才能向他发送通知。如果curlResult变量不起作用,请检查curlResult变量。 – luschn 2014-09-12 13:20:03
问,如果事情是可能的,你应该去看看Facebook的文档; ) – luschn 2014-09-12 11:21:22
我已经有了并使用旧的Facebook API,它似乎是可能的,但在新版本的4 SDK下,它们全都混在一起。我已经搜索了谷歌的所有例子等,无法找到任何接近新的SDK,这就是为什么我问你们的帮助和建议。 – widget 2014-09-12 11:34:19
我不会使用sdk来实现简单的应用程序通知,但一些简单的curl调用已经足够好了。我会回答一些有用的链接。 – luschn 2014-09-12 11:45:14