duanbin198788 2013-11-20 10:59
浏览 57
已采纳

Facebook通知的cURL循环

I'm trying to send our users notifications via our Facebook app.

Probably to the tune of 50-100 at a time, and can't seem to get the cURL to loop through...I can get one to send, but that's it. Sure I'm just missing something simple, but would love some other sets of eyes on it!

The code is:

<?php

include('../inc.php');

//App Access Token
$appat = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=xxxxxxxxxx&client_secret=xxxxxxxxxxx&grant_type=client_credentials");
parse_str($appat);

//Notify
$sql = "SELECT * FROM ats";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
    $userid = $row['UserID'];
    $url = "https://graph.facebook.com/$userid/notifications";
    $attachment =  array(   
                     'access_token'  => "$access_token",
                     'href' =>  "?a=1",
                     'template' => "Template Message",
                     'ref'          => "ActT"
                   );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    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, $attachment);
    //curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    $result = curl_exec($ch);
    curl_close ($ch);
}
include('../inc2.php');
?>
  • 写回答

1条回答 默认 最新

  • douqiao3930 2013-11-20 23:52
    关注

    Thanks for the responses guys! The Facebook SDK wasn't an option unfortunately, and after some research, this solved my problem:

    <?php
    include('../inc.php');
        $mh = curl_multi_init();
    $appat = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=xxxxxxxxxx&client_secret=xxxxxxxx&grant_type=client_credentials");
    parse_str($appat);
    
    
    $sql = "SELECT * FROM ats";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
    $i = $row['ID'];
    echo $i;
    
        $userid = $row['UserID'];
        $url = "https://graph.facebook.com/$userid/notifications";
    
        $attachment =  array(   'access_token'  => "$access_token",
                            'href'  =>  "?a=1",
                            'template'  => "Template Message",
                            'ref'          => "DanceCouple"
                        );
        ${'ch_' . $i} = curl_init();
        curl_setopt(${'ch_' . $i}, CURLOPT_URL,$url);
        curl_setopt(${'ch_' . $i}, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt(${'ch_' . $i}, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt(${'ch_' . $i}, CURLOPT_POST, true);
        curl_setopt(${'ch_' . $i}, CURLOPT_POSTFIELDS, $attachment);
    
     // build the multi-curl handle, adding both $ch    
        curl_multi_add_handle($mh, ${'ch_'.$i});
    
    }    
    
        $running = null;
        do {
            curl_multi_exec($mh, $running);
        } while ($running);
    
    
        include('../inc2.php');
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?