i'm trying make photo upload, but i'm not getting, well the goal was publish in my fan page wall, i cann't, so i decided to test in my wall "me/photo", same thing, this error appears!
CurlException failed creating formpost data
this is my code, and the page "config.php" contains only configurations, appid, secret, etc...
anyway, What am i do wrong?
$photo = '/imagens/teste.jpg'; // Path to the photo on the local filesystem
$message = 'Photo upload via the PHP SDK!';
?>
<html>
<head></head>
<body>
<?php
if($idUsuario) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'access_token'=> $facebook->getAccessToken(),
'source' => '#'.$photo,
'message' => $message
)
);
echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
echo '<br />logout';
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
echo 'Please login.';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
// To upload a photo to a user's wall, we need photo_upload permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo 'Please login.';
}
?>
</body>
</html>
You can see that this code is the same code example in dvelopers.facebook to make upload!
You must send the realpath to the API.
Change:
$photo = '/imagens/teste.jpg';
By:
$photo = realpath('/imagens/teste.jpg');
And check if your path is good.
Related
My code working fine in localhost but after uploading in server i am getting this error -> Forbidden
You don't have permission to access /admin/add.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
searched about it but didnt get a proper solution asked in fb grps as-well. and one more thing there is no .htaccess file in root folder. tried to add .htaccess file in server but didn't work as-well. I am using summernote in textarea previously i used tinymce but getting same error. its work fine without summernote/tinymce . textarea type is mediumtext
add.php
<?php
include_once('../includes/config.php');
//if form has been submitted process it
if(isset($_POST['submit'])){
$_POST = array_map( 'stripslashes', $_POST );
//collect form data
extract($_POST);
//very basic validation
if($category_id ==''){
$error[] = 'Please select the category id.';
}
if($cam_unique_id ==''){
$error[] = 'Please enter the cam unique id.';
}
if($cam_features ==''){
$error[] = 'Please enter cam feature.';
}
if(!isset($error)){
try {
//insert into database
$stmt = $db->prepare('INSERT INTO cam_details (category_id,subcategory_id,cam_unique_id,cam_name,brand,cam_features,cam_spec_t1,cam_spec_t2,cam_spec_t3,cam_spec_t4,cam_spec_t5,cam_spec_t6,cam_spec1,cam_spec2,cam_spec3,cam_spec4,cam_spec5,cam_spec6) VALUES
(:category_id, :subcategory_id, :cam_unique_id, :cam_name, :brand, :cam_features, :cam_spec_t1, :cam_spec_t2, :cam_spec_t3, :cam_spec_t4, :cam_spec_t5, :cam_spec_t6,:cam_spec1, :cam_spec2, :cam_spec3, :cam_spec4, :cam_spec5, :cam_spec6)') ;
$stmt->execute(array(
':category_id' => $category_id,
':subcategory_id' => $subcategory_id,
':cam_unique_id' => $cam_unique_id,
':cam_name' => $cam_name,
':brand' => $brand,
':cam_features' => $cam_features,
':cam_spec_t1' => $cam_spec_t1,
':cam_spec_t2' => $cam_spec_t2,
':cam_spec_t3' => $cam_spec_t3,
':cam_spec_t4' => $cam_spec_t4,
':cam_spec_t5' => $cam_spec_t5,
':cam_spec_t6' => $cam_spec_t6,
':cam_spec1' => $cam_spec1,
':cam_spec2' => $cam_spec2,
':cam_spec3' => $cam_spec3,
':cam_spec4' => $cam_spec4,
':cam_spec5' => $cam_spec5,
':cam_spec6' => $cam_spec6
));
//redirect to index page
header('Location: index.php');
exit;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
}
//check for any errors
if(isset($error)){
foreach($error as $error){
echo '<p class="error">'.$error.'</p>';
}
}
?>
try to add includes folder in admin directory and change the coding to
include_once('includes/config.php');
I am using this code to get the user friend's list. For profile picture i am unable to find any reference please guide if you know the process
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$iLimit=99;
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$user_profile = $facebook->api('/me','GET');
echo"<h3>";
echo 'Name: ' . $user_profile['name'];
echo"</h3>";
$profile_pic = "http://graph.facebook.com/".$user_id."/picture";
echo "<img src=\"" . $profile_pic . "\" />";
$user_friends = $facebook->api('/me/friends', 'GET' );
print_r($user_friends); //Given NULL Value
echo "</pre>";\
Returning null value
Please refer to the facebook graph api docs
https://developers.facebook.com/docs/graph-api/reference/friend-list/
and here is the code with tutorial
http://www.sanwebe.com/2011/10/facebook-friends-list-pagewise-with-php
Hope it helps !
I am using PinterestPinner to create an script that could login once and post multiple pins, rather than login each time I want to post a pin.
This is how I am using it:
foreach ($links as $link)
{
$pinterest = new PinterestPinner($username, $password);
$result = $pinterest->pin(array(
'board' => $boardId,
'image' => $image,
'description' => $description,
'link' => $url,
));
if (false === $result) {
echo 'Error: ' . $pinterest->getError();
} else {
echo 'Pin Created, ID: ' . $pinterest->getPinID();
}
}
I think using it this way makes the script login to Pinterest for every single pin. So for example, if I want to post 3 pins in a single script run, then it logs in 3 times rather than logging in once. (Please let me know if I am wrong about this).
How can I modify the script to keep the login session alive while posting multiple pins on my board?
Use This
try {
$pinterest = new PinterestPinner\Pinner;
$pin_id = $pinterest->setLogin('Your Pinterest Login')
->setPassword('Your Pinterest Password')
->setBoardID('Pinterest Board ID')
->setImage('Image URL')
->setDescription('Pin Description')
->setLink('Pin Link')
->pin();
} catch (PinterestPinner\PinnerException $e) {
echo $e->getMessage();
}
I have a quiz application on Facebook. It uploads a photo to user's photos at the end of the quiz.
$photo_upload = $facebook->api('/me/photos', 'POST', array(
'source' => '#' . './images/userimg.png',
'message' => $message,
)
);
But it is a sample image, the same for everyone. I want to make it personal by writing the user's name on the image. Part of create-img.php:
try {
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e) {
error_log($e);
$user_id = null; }
$username = iconv("UTF-8", "ISO-8859-2", $user_profile['name']);
$text = iconv("ISO-8859-2", "UTF-8", "Hello ". $username);
...
header('Content-type: image/png') ;
ImagePNG($image) ;
ImageDestroy($image) ;
imagepng($image, "./images/imgs_to_post/sample_userimg.png");
exit ;
It can be included in HTML, works fine, the image shows up with the user's name.
<img src="create-img.php" alt="" />
But when I try to put create-img.php as source in the API call above, i get an error.
Fatal error: Uncaught OAuthException: (#1) An unknown error occurred thrown in /home/mmdesign/public_html/.../php-sdk/base_facebook.php on line 1128
How can I put the result image of imagepng in the API call as source?
Thank you in advance.
But when I try to put create-img.php as source in the API call above, i get an error.
Of course, because that file contains PHP code, not image data. (If you think the PHP code is parsed at this point, you’re wrong.)
Write the image to HDD first, and then feed the API the path to that image.
I use this script here for my Facebook App.
It uploads a photo on a user's Facebook profile, and creates a new album for that photo.
The script returns "[APP NAME] Photos" as the Album name / title (without quotations).
- [APP NAME] being the name of my Facebook APP -
Basically, I don't want that Album title. I want to specify an Album title on the script.
What I want is :
... to be able to specify the Album's name / title to create, from the script.
And if possible, specify Album description too.
This is the script -
$root_url = "http://www.WEBSITE.COM/";
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
// Get image from URL
$img = $_GET['i'];
// Change location depending on which type of cover
if($get_set != 1) {
$photo = './PATH/'.$img.''; // Path to the photo on the local filesystem
} else {
$photo = './PATH/'.$img.'';
}
$message = 'THIS IS THE PHOTO CAPTION';
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => '#' . $photo,
'message' => $message,
)
);
// echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
print "<script>window.location = '".$root_url."index.php?cover=uploaded'</script>";
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
echo '<script> window.location = "' . $login_url . '"; </script>';
error_log($e->getType());
error_log($e->getMessage());
}
echo '<br />logout';
} else {
// No user, print a link for the user to login
// To upload a photo to a user's wall, we need photo_upload permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo '<script> window.location = "' . $login_url . '"; </script>';
//echo 'Please login to continue.';
}
Seeing this one here, I am confident that is possible.
$album_name = 'YOUR_ALBUM_NAME';
$album_description = 'YOUR_ALBUM_DESCRIPTION';
I just don't know how to work it in there...
Looking forward to solutions. Thanks for your time!
As it says in the documentation of the Photo object:
you can upload a photo by issuing an HTTP POST request with the photo
content and an optional description to one these to Graph API
connections:
https://graph.facebook.com/USER_ID/photos - The photo will be published to an album created for your app. We automatically create an
album for your app if it does not already exist. All photos uploaded
this way will then be added to this same album.
https://graph.facebook.com/ALBUM_ID/photos - The photo will be published to a specific, existing photo album, represented by the
ALBUM_ID. Regular albums have a size limit of 200 photos. Default
application albums have a size limit of 1000 photos.
You are currently using the first option, using the 2nd one requires for you to have an album id, which you first need to create:
You can create an album for a user by issuing an HTTP POST request to
PROFILE_ID/albums with the publish_stream permissions and the
following parameters
(Albums connection of the User object)
The problem is that you'll have to save this album id for the user to use in the future when the app needs to upload again to the album.