doucheng4660 2015-03-23 09:25
浏览 44

在Facebook中使用变量for post id删除请求PHP

I am using

$access_token =  $facebook->getAccessToken();
        $facebook->setAccessToken($access_token);
            $response = $facebook->api(
            $post_id['id'],
            'DELETE'
            );

to delete a post from a Facebook page. I have the post id stored in mysql database and use

 $ad_id = osc_ad_id();
$conn = getConnection();
    $get_id=$conn->osc_dbFetchResult("SELECT * FROM %st_post_id WHERE ad_id = '$ad_id'");
    $post_id = $get_id['post_id'];

to retrieve the id.

When I test it on my site and press the delete button it comes up with

Fatal error: Uncaught GraphMethodException: Unsupported delete request.

Although if I do it manually, and make $post = '5768877877667657_76576687667' (fake id) then change the code

$access_token =  $facebook->getAccessToken();
            $facebook->setAccessToken($access_token);
                $response = $facebook->api(
                $post_id,
                'DELETE'
                );

it works and deletes the post.

So my question is what is the difference between retrieving the id from mysql and doing it manually ($post_id = '576768687878_7676765857875'.

My row settings on mysql are type: varchar, collation: utf8_general_ci, and length: 50.

I have researched on stackoverflow for the solution but can't find anything.

I have also retreived the id on another page and then used echo to see if the format is correct, and it works, I even copied the echoed id and made $post_id equal to it, and it successfully deletes the post.

The request only fails when I retreive the id from the database and make it equal a variable.

  • 写回答

1条回答 默认 最新

  • doushi3803 2015-03-23 09:54
    关注

    mysql functions are deprecated, Please use mysqli functions instead. In your code.

    $post_id= msql_query("SELECT * FROM %st_post_id WHERE ad_id = '$ad_id'");
    

    $post_id will be a result set. If you want to get each column of the result set . You need to use either mysql_fetch_array() or mysql_fetch_row(). So please add this code to get post_id and try to run your script.

     $post_sql= msql_query("SELECT * FROM %st_post_id WHERE ad_id = '$ad_id'");
     $post_details = mysql_fetch_array($post_sql);
     $post_id = $post_details['id'];
     $access_token =  $facebook->getAccessToken();
            $facebook->setAccessToken($access_token);
                $response = $facebook->api(
                $post_id,
                'DELETE'
                );
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答