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/
Related
I am trying to write a script that will post an update to a facebook page timeline. I created an app and created a key for the app. I am using the code below:
require_once HOME_PATH . '/include/facebook/facebook.php';
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_APP_SECRET,
'cookie' => true,
'scope' => 'publish_stream',
));
$user_id = $facebook->getUser();
$access_token = $facebook->getAccessToken();
$attachment = array(
'access_token' => $access_token,
'message' => 'this is my message',
'name' => 'name',
'link' => ROOT_URL . $blog_data['url'] . '.htm',
'caption' => $blog_data['title'],
'description' => $blog_data['title'],
);
if ($image = get_first_image($blog_data['body'])) {
$attachment['picture'] = $image;
}
$facebook->api(FACEBOOK_BLOG_PAGE . '/feed', 'post', $attachment);
i think this key is connected to the app and not to my user, so it sounds like i would have to grant the permission within facebook, but i have seen some other posts telling me that i need to do this in code. The examples aren't very clear.
I know similar questions have been asked but i haven't seen any clear answers yet. Can anyone please clarify this?
If you want to get user_id by this piece of code: $user_id = $facebook->getUser();
The first thing you need, is to login an user through a URL returned by $facebook->getLoginUrl(array('scope' => array('perm', 'perm2'))).
Also, notice, where I put permissions, which I require. Not into the Facebook class constructor, but into the method getLoginUrl.
And lastly, for posting into a page, you need publish_actions permission (not publish_stream).
I am able to retrieve my fb comment using https://graph.facebook.com/comments/?ids=id, but i am not able to post comment back to fb, below is my code, please give me some guide
$accessToken = 'xxxxxxxxxxxxxxxxxx';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxx',
'secret' => 'xxxxxxxxxx',
));
$ret_obj = $facebook->api('/appid/comments', 'POST',
array(
'access_token' => $accessToken,
'message' => $comemnts
)
);
echo 'success...';
This is wrong
$facebook->api('/appid/comments', 'POST',
it should be like this
api('xxxxxxxxxxxx_xxxxxxxxxxxx_xxxxxxxxxxxx', 'POST
Where the
1st of the 3 xxx parts is the id of facebook page,
2nd is the id of the post
3ed is the id of the comment you are trying to comment.
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.
As per usual, FB has me pulling out my hair.
I've been able to test my app in IE9, but when using Firefox, after a user authorizes the canvas app it goes into a redirect loop, adding state and code variables to the URL.
I'm using the javascript and php sdk with this code:
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $application_secret,
'cookie' => true, // enable optional cookie support
));
$user = $facebook->getUser();
if(!($user))
{
echo"<script> top.location.href='" . $facebook->getLoginUrl(array('redirect_uri'
=> $fbconfig['appBaseUrl'],
'scope' => 'manage_notifications,publish_stream,publish_actions'
)) . "'</script>";
exit();
}
I read about adding this:
if (window.location.hash =='#=') window.location.hash=''; but it didn't seem to do anything.
I had the same issue on my latest app.
Solved it by using the code above in the < head > section.
Don't forget to upgrade your PHP SDK to the latest version.
<?
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'YYY',
));
$user = $facebook->getUser();
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_likes'
));
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
?>
I'm trying to post to my facebook group wall but I keep on getting the above error. Can anyone please tell me what I might be doing wrong here? I have checked the Facebook documentation but I still can't seem to fix it myself. My code is as follows:
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'perms' => 'offline_access, user_groups, publish_stream',
'cookie' => true
));
$result = $facebook->api(
'/xxxxxxxxxgroupid/feed/',
'post',
array('access_token' => $facebook->getAccessToken(), 'message' => 'Playing around with FB Graph..')
);
I think you need user_groups extended permission.
Use Try before, that sould work fine
try {
$params = array(
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png",
);
$post = $facebook->api("/$user/feed","POST",$params);
echo "Your post was successfully posted to UID: $user";
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}