I'm trying to upload image from a Facebook app. I get the following error: Fatal error: Uncaught CurlException: 26: failed creating formpost data thrown in /storage/content/00/103300/gjutveckling.se/public_html/fb/src/base_facebook.php on line 886
This is my code. The strange thing is that i got it to work, but then all if the sudden it stopped working. Can this be a SSL related problem, I just got a new one? Any suggestions must appreciated!
<?php
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'fileUpload' => true,
'cookie' => true,));
$facebook->setFileUploadSupport(true);
$FILE_PATH = 'imdage_' . $user_id . '.jpg';
$args = array('message' => 'message');
$args['image'] = '#' . realpath($FILE_PATH);
$data = $facebook->api('/me/photos', 'post', $args);
?>
I tried this aswell, it doesn't give me an error, but no photo is uploaded.
<?php
function upload_to_facebook($image_data, $access_token)
{
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxx',
));
$facebook->setFileUploadSupport(true);
$albums = $facebook->api('/me/albums', 'get', array('access_token' => $access_token));
foreach ($albums[data] as $album)
{
if ($album['name'] == $image_data['album_name'])
{
$album_id = $album['id'];
}
}
if (!$album_id)
{
//Create an album
$album_details = array(
'message' => 'Album by FB APP',
'access_token' => $access_token,
'name' => $image_data['album_name']
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you’ve just created
$album_id = $create_album['id'];
}
//Upload a photo to album of ID…
$photo_details = array(
'message' => 'test image',
'access_token' => $access_token,
);
$photo_details['skrivreglerny.png'] = '#' . realpath($image_data['file']);
$upload_photo = $facebook->api('/'.$album_id.'/photos', 'post', $photo_details);
return $upload_photo;
}
?>
Try this please
$photo_details = array(
'message' => 'message',
'access_token' => 'USER ACCESS TOKEN',
);
$photo_details['image'] = '#'.realpath($image_data['file']);
$upload_photo = $facebook->api(('/me/photos', 'post', $photo_details);
see this link
http://pramodsivadas.co.in/2011/11/upload-an-image-to-a-facebook-album-facebook-php-sdk/
Related
I am using Following code for auto post on Facebook, but it shows me an OAuthException.
$user_id = $facebook->getUser();
$page_info = $facebook->api("/PAGE_ID?fields=access_token");
try {
$ret_obj = $facebook->api(
'/PAGE_ID/feed',
'POST',
array (
'link' => 'http://www.example.com/',
'message' => 'This is a test',
'access_token' => $page_info['access_token']
)
);
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl(array(
'scope' => 'publish_stream'
));
print_r($e->getType());
print_r($e->getMessage());
}
Error:
Fatal error: Uncaught OAuthException: (#100) Tried accessing
nonexisting field (access_token) on node type (User) thrown in
/home/malwatal/public_html/basic/lib/base_facebook.php on line 1028
Now it's time to use facebook v5 sdk
$fb = new Facebook\Facebook([
'app_id' => 'app_id',
'app_secret' => 'app_secret',
'default_graph_version' => 'v2.8',
]);
// facebook auto post
$params = array(
"message" => "$title in $merchant $short",
"link" => "http://pickmyoffers.com/",
"picture" => "http://Pickmyoffers.com/images/searched/Flipkart.png",
"name" => "www.Pickmyoffers.com",
"caption" => "www.pickmyoffers.com",
"description" => "Submit Coupon and earn money through Pickmyoffers.com | Deals,Coupons and offers."
);
$post = $fb->post('/Page_id/feed',$params, $access_token);
$post = $post->getGraphNode()->asArray();
}
hope it's help
This code return "invalid album id".
if the user is admin fan page then it works.
But I need that all users can upload photos through the app in fan page album.
$config = array(
'appId' => '553412241404428',
'secret' => '...',
'fileUpload' => true, // optional
'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
'cookie' => true
);
// exist ALBUM from URL
$ALBUM_ID = "765349256813004";
$filename = $_GET['file'];
$facebook = new Facebook($config);
$facebook->setFileUploadSupport(true);
if(!$user = $facebook->getUser()) {
echo "<a target='_blank' href='".$facebook->getLoginUrl(array('scope' => 'publish_actions,publish_stream,user_photos,email,read_stream,manage_pages,user_groups'))."'>Auth</a>";
exit;
}
$access_token = $facebook->getAccessToken();
$FILE_PATH = $_SERVER['DOCUMENT_ROOT']."facebook/uploads/".$filename;
$args = array('message' => 'Photo Caption');
$args['image'] = '#' . realpath($FILE_PATH);
$args['access_token'] = $access_token;
$data = $facebook->api('/'. $ALBUM_ID . '/photos', 'post', $args);
print_r($data);exit;
I'm trying to make a script to automatically post a picture to my three fan pages.
Here is the script:
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'fileUpload' => true,
));
if($_GET["postType"] == "picture"){$type = "picture";}
else {$type = "link";}
// Download the picture, if $type == picture.
if($type == "picture")
{
$tempFileName = $_SERVER['DOCUMENT_ROOT'].'/TemporaryFiles/';
$tempFileName .= uniqid().'_'.basename($_GET["pictureUrl"]);
// Check if content retrieval is successful :D
if($imgContent = #file_get_contents($_GET["pictureUrl"]))
{
#file_put_contents($tempFileName,$imgContent);
}
}
foreach($pageIDs as $index=>$item)
{
$fbconfig['pageid'] = $item;
$facebook->setFileUploadSupport(true);
if($type == "picture")
{
$args = array(
'access_token' => $pageAccessTokens[$index],
'message' => $_GET["message"],
'source' => '#' . realpath($tempFileName),
);
$post_id = $facebook->api("/" . $albumIDs[$index] . "/photos","post",$args); // Post made :)
}
else if($type == "link")
{
$args = array(
'access_token' => $pageAccessTokens[$index],
'message' => $_GET["message"],
'link' => $_GET["linkUrl"],
'picture' => "",
);
$post_id = $facebook->api("/$pageid/feed","post",$args); // Post made :)
}
}
if($type == "picture")
{
unlink($tempFileName);
}
It's throwing out the following error:
Uncaught OAuthException: (#324) Requires upload file thrown in
I've tried to debug it and have no clue what's wrong with it. If anyone could help, would be grateful.
You need to add photo_upload to your requested scopes to upload images.
array('scope' => 'user_status,publish_stream,user_photos','photo_upload')
put this in your code after the $ facebook-> api ('/ me');
$this->facebook->setFileUploadSupport(true);
how to create an event of facebook using facebook application?
further i want to use graph api for that purpose,kindly help me out...
$access_token = 'app_access_token';
$url = "https://graph.facebook.com/app_id/events";
$postdata = "access_token=$access_token&name=$name&start_time=$start_time&end_time=$end_time&description=$description&privacy=$privacy&location=$location&picture=$picture_source";
$event_code = curl_sending_newsfeed_facebook($url, $postdata);
i have already done the creation of event but picture of event is not shown (i mean a picture represents the face of event)
try doing something like this,
$fb = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
'cookie' => false,
'fileUpload' => true
));
$imageFile = realpath('/path/to/your/example.jpg');
$eventInfo = array(
'name' => 'some title',
'start_time' => time()+32400,
'description' => 'some description',
basename($file) => '#'.$imageFile
);
$result = $fb->api(
'/'.$app_id.'/events',
'post',
$eventInfo
);
echo 'Created event #'.$result['id'];
How to create like this ?
Users from my website can Upload image to their FB page.
for example : myfbcover.com
I uploaded these files (https://github.com/facebook/php-sdk) .
Now what to Next ?
Please help me !
Basic example:
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'Album desc',
'name'=> 'Album name'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$photo_details = array(
'message'=> 'Photo message'
);
$file='app.jpg'; //Example image file
$photo_details['image'] = '#' . realpath($file);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
}
This is just an exmaple. You could find lots of sources on googling.
Hope it helps you get started