2014-10-07 61 views
2

我嘗試了下面的從Facebook輸出,因爲這需要一個職位。如何發送facebook通知給用戶使用curl沒有facebook SDK

$ch = curl_init('https://graph.facebook.com/appUserId/notifications?access_token=*****&href=index.php&template=test'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch,CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
$response = curl_exec($ch); 
var_dump($response); 
var_dump(json_decode($response)); 

然後從這我得到以下,我可能會做錯什麼?

string '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xml:lang="en" lang="en" id="facebook"> 
    <head> 
    <title>Facebook | Error</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta http-equiv="Cache-Control" content="no-cache" /> 
    <meta name="robots"    content="noindex,nofollow" /> 
    <style type="text/css"> 
     html, body { 
     margin:  '... (length=2131) 
null 

回答

2

可以使用這樣做很輕鬆地將其原生的Facebook PHP-SDK:

https://developers.facebook.com/docs/php/gettingstarted/4.0.0

下面是發送通知的API方法的文檔:https://developers.facebook.com/docs/graph-api/reference/v2.1/user/notifications

用法示例使用PHP-SDK :

/* PHP SDK v4.0.0 */ 
/* make the API call */ 
$request = new FacebookRequest(
    $session, 
    'POST', 
    '/{user-id}/notifications', 
    array (
    'href' => '/testurl?param1=value1', 
    'template' => 'This is a test message', 
) 
); 
$response = $request->execute(); 
$graphObject = $response->getGraphObject(); 
/* handle the result */ 
+0

我不想要的原因使用SDK是根本無法工作的。我甚至在這裏問了一個關於它的問題。 http://stackoverflow.com/questions/26219564/how-to-use-facebook-sdk-4-0-without-composer-with-autoloader – Underscore 2014-10-07 11:32:12

+0

得到了SDK的工作,但現在拋出一個錯誤,'$ session '是未定義的。 – Underscore 2014-10-07 14:44:36

+0

在進行此api調用之前,您是否正在創建Facebook應用程序會話?看看這個:https://developers.facebook.com/docs/php/FacebookSession/4.0.0 – Latheesan 2014-10-07 16:21:48

相關問題