如何使用cURL在facebook graph api请求 [英] how to use cURL in facebook graph api request

查看:295
本文介绍了如何使用cURL在facebook graph api请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用file_get_contents()获取信息到facebook graph api



但有时我收到一个错误。



我发现必须使用cURL而不是file_get_contents()。



问题是,我不知道如何使用cURL

  file_get_contents($ graph_url); 

到cURL中,代码是什么?



这里是$ graph_url的内容

  $ graph_url =https://graph.facebook.com/me/相片? 
。 url =。 urlencode($ photo_url)
。 & message =。 urlencode('')
。 & method = POST
。 & access_token =。$ access_token;


解决方案

  $ graph_url =https://graph.facebook.com/me/photos; 
$ postData =url =。 urlencode($ photo_url)
。 & message =。 urlencode('')
。 & access_token =。$ access_token;

$ ch = curl_init();

curl_setopt($ ch,CURLOPT_URL,$ graph_url);
curl_setopt($ ch,CURLOPT_HEADER,0);
curl_setopt($ ch,CURLOPT_POST,1);
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ postData);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,0);

$ output = curl_exec($ ch);

curl_close($ ch);


I am getting the information to facebook graph api using file_get_contents()

but sometimes I am receiving an error.

I found out that cURL must be used instead of file_get_contents().

The problem is, I don't know how to use cURL with the URL that I need to pass.

if I converted

file_get_contents($graph_url);

into cURL, what will be the code?

here is the content of $graph_url

$graph_url= "https://graph.facebook.com/me/photos?"
  . "url=" . urlencode($photo_url)
  . "&message=" . urlencode('')
  . "&method=POST"
  . "&access_token=" .$access_token;

解决方案

    $graph_url= "https://graph.facebook.com/me/photos";
  $postData = "url=" . urlencode($photo_url)
  . "&message=" . urlencode('')
  . "&access_token=" .$access_token;

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $graph_url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

        $output = curl_exec($ch);

        curl_close($ch);

这篇关于如何使用cURL在facebook graph api请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆