2014-09-12 89 views
0

有誰知道是否有可能通過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.

+1

問,如果事情是可能的,你應該去看看Facebook的文檔; ) – luschn 2014-09-12 11:21:22

+0

我已經有了並使用舊的Facebook API,它似乎是可能的,但在新版本的4 SDK下,它們全都混在一起。我已經搜索了谷歌的所有例子等,無法找到任何接近新的SDK,這就是爲什麼我問你們的幫助和建議。 – widget 2014-09-12 11:34:19

+0

我不會使用sdk來實現簡單的應用程序通知,但一些簡單的curl調用已經足夠好了。我會回答一些有用的鏈接。 – luschn 2014-09-12 11:45:14

回答

0

教程爲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); 
+0

感謝指針,我認爲curl方法由於版本4而停止,無論如何都不願意使用任何方法讓我開始朝着正確的方向前進。我有一個快速的看,它沒有工作,所以我猜我的FB應用程序設置有問題。今晚我會再看一次。謝謝你的幫助。 – widget 2014-09-12 12:31:56

+0

爲什麼? curl是一個基本的php功能,與php sdk沒有關係。而新的SDK也使用捲曲。 – luschn 2014-09-12 13:18:54

+0

順便說一句,當然用戶必須先授權你的應用程序,然後才能向他發送通知。如果curlResult變量不起作用,請檢查curlResult變量。 – luschn 2014-09-12 13:20:03