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.
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 have a big problem, I try to publish a post from an Facebook app to a Facebook page wall.
I used this function to do so :
function Post_facebook($message){
include_once('php-sdk/facebook.php');
$app_config = array(
'appId' => '*********',
'secret' => '************');
$page_config = array(
'access_token' => '********',
'page_id' => '*********');
$facebook = new Facebook($app_config);
$params = array(
'access_token' => $page_config['access_token'],
'message' => $message);
$post_id = $facebook->api('/'.$page_config['page_id'].'/feed','post',$params);
}
Everything seems to be ok, but only I can see the posts.
When I'm on the wall everything seems normal, I see posts from the app. But if someone else goes on the wall, he won't be able to. Publication are set to 'Public' on privacy settings so I can't see why it's not working.
If I go to post URL (https://www.facebook.com/*****/posts/*****) from another account it says : page doesn't exist....
You need to disable sandbox-mode from your Facebook app's settings
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 am attempting to build a website that utilizes facebook auth based setting created through facebook.com/developers
Can I access a user’s wall (to post), multi friend selector and other elements if the website is hosted outside of facebook.com (apps.facebook.com) realm?
Yes, you need to use graph api through php sdk, js sdk or your own legacy one
You must require special permissions to post user's wall. Use a standard api mechanism to get access_token from user. Make sure user accepted the application permissions requirements such as offline_access, publish_stream etc.
public function friend_off()
{
$home_view = 'offline';
$this->load->library('facebook',array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$this->load->database();
$this->db->where('status', 'A');
$db_user = $this->db->get('users');
//$db_user = $this->db->where('access_pass',$val));
$row = $db_user->result();
//print_r($row);
//friends list
$post = array(
'from' => array(
'access_token' => '1302623452|1212291707|Dgz0FpB0wL0n5PYLy2x--5iGRVo',
'name' => 'Syama Varyar',
'id' => '100002653867222'
),
'to' => array(
'name' => 'Vishnu Jayendran',
'id' => '558987909'
),
'caption' => 'Test Caption',
'description' => 'Test Description',
'picture' => 'http://www.najeem.com/bird-2003.gif',
'message' => 'Test Message >> '. date('Y-m-d H:i:s'),
);
$friends = $this->facebook->api('/100002653867222/friends?access_token=1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
//$this->print_p($friends);
$this->facebook->setAccessToken('1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
if(!($res = $this->facebook->api('/me/feed', 'POST', $post)))
{
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}
for some reason my facebook app is posting to the wall of the user who allowed the app, and not their friends like it's suppose to.
I'm just using a
$facebook->api_client->stream_publish($message, $target_id);
Anyone got any ideas?
If you're just starting out, you might find the Graph API and the new PHP SDK to be easier. For example:
<?php
require './facebook.php';
$fb = new Facebook(array(
'appId' => 'YOUR APP ID',
'secret' => 'YOUR API SECRET',
'cookie' => true, // enable optional cookie support
));
$post = $fb->api("$target_id/feed", 'POST', array('message' => $message));
The various parameters are documented at the bottom here.
Yeah, you aren't using the right method signature. Here it is as copied from my copy of the file
public function stream_publish(
$message, $attachment = null, $action_links = null, $target_id = null,
$uid = null) {
So you'd need to call it like so
$facebook->api_client->stream_publish( $message, null, null, $target_id );