[英]PHP SCRIPT issue with passing the uploaded image to facebook->api function
I have this code and its working awsomely fine if i provide a direct link of an image. 如果我提供图像的直接链接,则我有这段代码,它的工作效果非常好。
Just and just only one problem i am not able to pass my uploaded image to facebook->api (whether its valid or not) and the following always echo 仅有的一个问题,我无法将上传的图像传递给facebook-> api(无论其是否有效),并且以下内容始终会出现
echo 'Only jpg, png and gif image types are supported!'; echo'仅支持jpg,png和gif图像类型!
i even remove the check on image type and try to get the image from $img = realpath($_FILES["pic"]["tmp_name"]); 我什至取消了对图像类型的检查,并尝试从$ img = realpath($ _ FILES [“ pic”] [“ tmp_name”])获取图像。 but $img gets nothing in it and uploads a by default empty image on facebook as my page Kindly check my following code and let me know what is wrong with my code and what should i do instead to upload images
但是$ img却什么也没有,并且默认在我的页面上在Facebook上上传一个空图像请检查我的以下代码,并让我知道我的代码有什么问题,我应该怎么做才能上传图像
Online link of the following CODE: http://radiations3.com/facebook/1.php 以下代码的在线链接: http : //radiations3.com/facebook/1.php
<?
require 'src/facebook.php';
$app_id = "364900470214655";
$app_secret = "xxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'fileUpload' => true,
));
$user = $facebook->getUser();
//echo $user;
if(($facebook->getUser())==0)
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
exit;
}
else {
$accounts_list = $facebook->api('/me/accounts');
echo "i am connected";
}
$valid_files = array('image/jpeg', 'image/png', 'image/gif');
//to get the page access token to post as a page
foreach($accounts_list['data'] as $account){
if($account['id'] == 194458563914948){ // my page id =123456789
$access_token = $account['access_token'];
echo "<p>Page Access Token: $access_token</p>";
}
}
//posting to the page wall
if (isset($_FILES) && !empty($_FILES))
{
if( !in_array($_FILES['pic']['type'], $valid_files ) )
{
echo 'Only jpg, png and gif image types are supported!';
}
else{
#Upload photo here
$img = realpath($_FILES["pic"]["tmp_name"]);
$attachment = array('message' => 'this is my message',
'access_token' => $access_token,
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'example.org',
'description' => 'this is a description',
'picture' => '@' . $img,
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$status = $facebook->api('/194458563914948/feed', 'POST', $attachment); // my page id =123456789
var_dump($status);
}
}
?>
<body>
<!-- Form for uploading the photo -->
<div class="main">
<p>Select a photo to upload on Facebook Fan Page</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<p>Select the image: <input type="file" name="pic" /></p>
<p><input class="post_but" type="submit" value="Upload to my album" /></p>
</form>
</div>
</body>
Upon uploading, i received the following callback 上传后,我收到了以下回调
i am connectedarray(1) { ["id"]=> string(31) "194458563914948_415487041812098" }
我是connectedarray(1){[“ id”] => string(31)“ 194458563914948_415487041812098”}
graph api explorer suggests the upload was successful 图API资源管理器建议上传成功
https://developers.facebook.com/tools/explorer?method=GET&path=194458563914948_415487041812098 https://developers.facebook.com/tools/explorer?method=GET&path=194458563914948_415487041812098
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.