i have this code...
require_once "facebook.php";
$app_id = "xxxxxx";
$app_secret = "xxxxx";
$facebook = new Facebook(array(
"appId" => $app_id,
"secret" => $app_secret,
"cookie" => true
));
$random_file = rand();
copy('http://alylores.x10.mx/gd/clean2/pic.php', 'temp/'.$random_file.'.jpg');
$img = realpath("temp/".$random_file.".jpg");
// allow uploads
$facebook->setFileUploadSupport("http://" . $_SERVER['SERVER_NAME']);
// add a photo
$photo = $facebook->api("/".$_POST['fid']."/photos?access_token=".$_POST['foauth'],"POST",
array(
"source" => "#" . $img,
"message" => "This photo came from my app."
)
);
echo "<script type='text/javascript'>parent.iframe_callback();</script>";
unlink('temp/'.$random_file.'.jpg');
i'm trying to upload a photo into user's photos from an IFRAME.... facebook id and oauth_token are passed using post request from the parent window..
and when i check... it returns this....
Fatal error: Uncaught OAuthException: A user access token is required to request this resource.
thrown in /home/alylores/public_html/gd/clean2/base_facebook.php on line 1033
but when i check if the oauth_token exists by echo()
the oauth_token does exist....
can someone help me work this out please???
array( "access_token" => $_POST["foauth"], "source" => "#" . $img, "message" => "This photo came from my app." )
Related
I keep getting this Every from Facebook when i hybridauth-2.5.1 when use this code below.
Invalid Scopes: read_stream. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: https://developers.facebook.com/docs/facebook-login/permissions
$config = dirname(__FILE__) . '/config.php';
require_once( "Hybrid/Auth.php" );
$hybridauth = new Hybrid_Auth( $config );
// try to authenticate with Facebook
$adapter = $hybridauth->authenticate( "Facebook" );
// return Hybrid_User_Profile object intance
$user_profile = $adapter->getUserProfile();
echo "Hi there! " . $user_profile->displayName;
If anyone has the same Problem this was the solution
"Facebook" => array(
"enabled" => true,
"keys" => array("id" => "162293657470362", "secret" =>
"109552243da7661c3a1c7bb90670c858"),
"scope" => "email, user_about_me, user_birthday, user_hometown",
"trustForwarded" => false
)
I'm trying to post photo on user wall and tag friends but i'm getting this :
Fatal error: Uncaught OAuthException: (#324) Requires upload file
thrown in /home/vhosts/somesite.com/src/base_facebook.php on line 1238
This is my code
<?php
require_once "./src/facebook.php";
$app_id = "xxxxxxxx";
$app_secret = "xxxxxxxxxx";
// Init facebook api.
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// Get the url to redirect for login to facebook
// and request permission to write on the user's wall.
$login_url = $facebook->getLoginUrl(
array('scope' => 'publish_stream')
);
$loginUrl = $facebook->getLoginUrl($params);
// If not authenticated, redirect to the facebook login dialog.
// The $login_url will take care of redirecting back to us
// after successful login.
if (! $facebook->getUser()) {
echo <<< EOT
<script type="text/javascript">
top.location.href = "$login_url";
</script>;
EOT;
exit;
}
// Do the wall post.
$args = array(
'message' => 'Test Message',
'image' => '#' . realpath('http://imageurl.com'),
'tags' => array(
array(
'tag_uid'=> $friend1_uid,
'x' => $x1,
'y' => $y1,
),
array(
'tag_uid' => $friend2_uid,
'x' => $x2,
'y' => $y2,
),/*...*/
),
);
$data = $facebook->api('/me/photos', 'post', $args);
// Upload Support.
$facebook = new Facebook(array(
/*..*/
'fileUpload' => true,
));
?>
'image' => '#' . realpath('http://imageurl.com'),
realpath is for file system paths, not for URLs.
Either change that to a local file system path – or, if you want to upload a photo from a publicly available HTTP URL, use parameter name url instead of source and give the URL as value.
I have problems to upload a photo to an album by the facebook API. this is my code.
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'Message',
'name'=> 'Album Name'
);
$create_album = $facebook->api('/me/albums?access_token='.$access_token, 'post', $album_details);
//Get album ID of the album you've just created
$album_id = $create_album['id'];
echo $album_id." - ";
//Upload a photo to album of ID...
$photo_details = array();
$img = "app.jpg";
$photo_details['source'] = '#' . $img;
$photo_details['message'] = 'Wow.. cool image!';
$upload_photo = $facebook->api('/'.$album_id.'/photos?access_token='.$access_token, 'post', $photo_details);
When i upload the image with a form, it works! but this code does not upload the image into the album.
I have tried also with CURL but there is nothing... i don't know where the problem is...
After testing few things on Graph API Explorer, Here's a working PHP Version:
<?php
# Path to facebook's PHP SDK.
require_once("facebook.php");
# Facebook application config.
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'fileUpload' => true # Optional and can be set later as well (Using setFileUploadSupport() method).
);
# Create a new facebook object.
$facebook = new Facebook($config);
# Current user ID.
$user_id = $facebook->getUser();
# Check to see if we have user ID.
if($user_id) {
# If we have a user ID, it probably means we have a logged in user.
# If not, we'll get an exception, which we handle below.
try {
# Get the current user access token:
$access_token = $facebook->getAccessToken();
# Create an album:
$album_details = array(
'access_token' => $access_token,
'name' => 'Album Name',
'message' => 'Your album message goes here',
);
$create_album = $facebook->api('/me/albums', 'POST', $album_details);
# Get album ID of the album you've just created:
$album_id = $create_album['id'];
# Output album ID:
echo 'Album ID: ' . $album_id;
# Upload photo to the album we've created above:
$image_absolute_url = 'http://domain.com/image.jpg';
$photo_details = array();
$photo_details['access_token'] = $access_token;
$photo_details['url'] = $image_absolute_url; # Use this to upload image using an Absolute URL.
$photo_details['message'] = 'Your picture message/caption goes here';
//$image_relative_url = 'my_image.jpg';
//$photo_details['source'] = '#' . realpath($image_relative_url); # Use this to upload image from using a Relative URL. (Currently commented out).
$upload_photo = $facebook->api('/' . $album_id . '/photos', 'POST', $photo_details);
# Output photo ID:
echo '<br>Photo ID: ' . $upload_photo['id'];
} 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' => 'publish_stream, user_photos'));
echo 'Please login.';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
# No user, print a link for the user to login and give the required permissions to perform tasks.
$params = array(
'scope' => 'publish_stream, user_photos', # These permissions are required in order to upload image to user's profile.
);
$login_url = $facebook->getLoginUrl($params);
echo 'Please login.';
}
?>
I have added comments so you could understand what it does by reading the code.
This works with both absolute url and relative url, I have commented out code for uploading image using relative url as you have mentioned in your comments you can't read real path of the image.
EDIT: Note: The user has to give extended permissions to your facebook application to upload images to their profile, Those permissions are publish_stream and user_photos.
Let me know if this helped you and if it works :)
$user = $this->facebook->getUser();
$this->facebook->setFileUploadSupport(true);
$user_profile = $this->facebook->api('/me');
$album_details = array(
'message' => 'Hello everybody this is me ' . $user_profile['name'],
'name' => 'I am so slim because I dont have money to eat....:('
);
$create_album = $this->facebook->api('/me/albums', 'post', $album_details);
// Upload a picture
$photo_details = array(
'message' => 'I am so slim because I dont have money to eat....:('
);
$photo_details['image'] = '#' . realpath('./a.jpg');
$upload_photo = $this->facebook->api('/' . $create_album['id'] . '/photos', 'post', $photo_details);
Please use $facebook on $this->facebook
I have a music blog and would like to duplicate all my posts to facebook, but I can't get the api to post streaming audio like I can when I post manually. It does actually post, but the audio is stripped out. Here is my code:
<?php
require 'facebook-php-sdk/src/facebook.php';
$APP_ID = 'MYAPPID';
$APP_SECRET = 'MYAPPSECRET';
$PAGE_ID = 'MYPAGEID';
$ACCESS_TOKEN = 'GENERATEDACCESSTOKEN';
$facebook = new Facebook(array(
'appId' => $APP_ID,
'secret' => $APP_SECRET,
'cookie' => true,
));
$attachment = array(
'message' => 'some message',
'attachment' => '{"media": [{"type": "mp3","src": "http://EXAMPLE.COM/music.mp3", "title": "title", "artist": "artist", "album":"album"}]}',
'access_token' => $ACCESS_TOKEN
);
$result = $facebook->api('/'.$PAGE_ID.'/feed', 'post', $attachment);
if($result){
echo "<p>Posted status update</p>";
}
else {
echo "<p>Unable to post update.</p>";
}
?>
Any Idea how I can fix this? Thanks y'all
That's not possible, only whitelisted partners are able to use Open Graph Music tags.
More info here - https://developers.facebook.com/docs/opengraph/music/
I try to post on my wall using facebook api, and offline access tokens.
And every time I has one mistake:
Uncaught OAuthException: (#200) The user hasn't authorized the
application to perform this action
Here is my code:
require 'api/facebook.php';
$facebook = new Facebook(array(
'appId' => "app_id",
'secret' => "app_sec",
"cookie" => true,
'fileUpload' => true
));
$facebook->setFileUploadSupport(true);
$access_token = $facebook->getAccessToken();
$user_id = $facebook->getUser();
$result = mysql_query("UPDATE users SET user_id_facebook='".$user_id."' WHERE id='".$myrow2['id']."'",$db);
$result = mysql_query("UPDATE users SET access_token_facebook='".$access_token."' WHERE id='".$myrow2['id']."'",$db);
if($user_id == 0 || $user_id == "")
{
$login_url = $facebook->getLoginUrl(array(
'redirect_uri' => "http://apps.facebook.com/rapid-apps/",
'scope' => "email,publish_stream,user_hometown,user_location,user_photos,friends_photos,
user_photo_video_tags,friends_photo_video_tags,user_videos,video_upload,friends_videos,offline_access"));
echo "<script type='text/javascript'>top.location.href = '$login_url';</script>";
exit();
}
$post = array(
'access_token' => $access_token,
'message' => 'This message is posted with access token - '
);
$res = $facebook->api('/me/feed', 'POST', $post);
as of may 2nd the offline_access permission will be deprecated and should not be used anymore
in the meantime you have an option to disable this deprecation through the developers site for your application ( https://developers.facebook.com/apps/330955886953999 )...
for further information about the removal see:
http://developers.facebook.com/roadmap/offline-access-removal/
You need to adjust the permissions in your initial app authorization request sent to the user. By default you only gain read-only access to their basic information.
See http://developers.facebook.com/docs/authentication/permissions/