Facebook 图片上传器(粉丝专页)

编程入门 行业动态 更新时间:2024-10-23 10:21:37
本文介绍了Facebook 图片上传器(粉丝专页)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的代码,我试图卷曲"它(file_get_contents 由于某种原因没有工作)但因为我无法真正得到Curl 工作,我是来寻求帮助的.

This is my code and I tried to "Curl" it (file_get_contents didn't work for some reason) but since i can't really get Curl to work, I came here to get some help.

我已经为此痛苦了 10 个小时,但我仍然找不到!!!请帮忙!!

I've been suffering with this for 10 hrs now and I still can't find out!!! please help!!

<?php $app_id = "xxxxx"; $app_secret = "xxxxx"; $fanpage_id ='3xxxxx'; $post_login_url = "xxxxxxxxxteszt.php"; $photo_url = "xxxxxxxxxx20130412104817.jpg"; $photo_caption = "sasdasd"; $code = $_REQUEST["code"]; //Obtain the access_token with publish_stream permission if (!$code) { $dialog_url= "www.facebook/dialog/oauth?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode( $post_login_url) . "&scope=publish_stream,manage_pages"; echo("<script>top.location.href='".$dialog_url."'</script>"); } if(isset($_REQUEST['code'] )) { print('<script>alert("asd");</script>'); function curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt( $ch, CURLOPT_POSTFIELDS, $url ); } $token_url="graph.facebook/oauth/access_token?" . "client_id=" . $app_id . "&client_secret=" . $app_secret . "&redirect_uri=" . urlencode( $post_login_url) . "&code=" . $code; print($code); $response = curl($token_url); print($response); $params = null; parse_str($response, $params); $access_token = $params['access_token']; // POST to Graph API endpoint to upload photos $graph_url= "graph.facebook/".$fanpage_id."/photos?" . "url=" . urlencode($photo_url) . "&message=" . urlencode($photo_caption) . "&method=POST" . "&access_token=" .$access_token; echo '<html><body>'; echo curl($graph_url); echo '</body></html>'; } ?>

推荐答案

您不能只将 url 传递给 CURLOPT_POSTFIELDS 选项.在CURLOPT_URL选项中设置基本url,在CURLOPT_POSTFIELDS中设置参数(使用PHP的http_build_query函数生成编码查询字符串);

You can't just pass the url to the CURLOPT_POSTFIELDS option. The base url should be set in the CURLOPT_URL option, and the parameters in CURLOPT_POSTFIELDS (using PHP's http_build_query function to generate the encoded query string);

所以你的 curl 函数可能看起来像这样:

So your curl function could look something like this:

function curl($url,$parms) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parms, null, '&')); }

然后你会这样称呼它:

$token_url="graph.facebook/oauth/access_token"; $token_parms = array( "client_id" => $app_id, "client_secret" => $app_secret, "redirect_uri" => $post_login_url, "code" => $code ); $response = curl($token_url, $token_parms);

更多推荐

Facebook 图片上传器(粉丝专页)

本文发布于:2023-06-05 19:40:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/526463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片上传   粉丝   专页   Facebook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!