Posting to my wall instead of others wall FBML Facebook API - facebook

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 );

Related

Trying to post to facebook page with app but get "The user hasn't authorized the application to perform this action"

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).

How to post comments to facebook using open graph

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.

Facebook publication from app to page wall invisible to others

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

Get user's country at Facebook: getSignedRequest() results without 'user' field

Code:
$facebook = new Facebook(array(
'appId' => some_fb_app_id),
'secret' => some_fb_app_secret),
'cookie' => true,
));
$result = $facebook->getSignedRequest();
echo var_export($result,1);
Result:
array (
'algorithm' => 'HMAC-SHA256',
'code' => 'A.....l',
'issued_at' => 1354720771,
'user_id' => 'some_user_id',
)
I expect $result["user"]["country"] to be set. How can I fix this problem?
ps. by Facebook Graph API - how to get user country?
According to the facebook PHP SDK getSignedRequest() only gives you the signed request, just like the name suggests. User info is usually gotten through the Graph API, using calls like
$facebook->api('/me','GET');
which gives you the profile for the user associated with the access_token you are using.
Note that you will only ever get information that you have the permissions for, so if you haven't added a particular bit of info beyond the basics to your apps scope, you will not get it.

login from one domain and after that getting facebook object in another domain using php sdk 3.1.1

I am logining in and making the authentication processes from one domain (localhost)
$config = array(
appId' => $APP_ID,
'secret' => $APP_SECRET
);
$facebook = new Facebook($config);
$currentUserId = $facebook->getUser();
This works fine and i get an Access Token and a user id.
After that. from the browser i am making a post action to a php file on a remote domain
in the remote php i use the same code the same APP_ID and the same APP_SECRET
$config = array(
'appId' => $APP_ID,
'secret' => $APP_SECRET
);
$facebook = new Facebook($config);
$currentUserId = $facebook->getUser();
this does not! work and get $currentUserId = 0
and that is my problem
I can use (but dont want to):
$facebook->setAccessToken($at);
with the acsess token from that i got form the localhost domain it does work and i get the user id
In older sdk 2.0 I have seen this function setBaseDomain
Is there a way i can use it in 3.1.1?
here's what I do - so when you make the request to the other domain pass along the access_token when you make the API call do something like this -
$config = array(
'appId' => $APP_ID,
'secret' => $APP_SECRET
);
$facebook = new Facebook($config);
$args['access_token'] = $_POST['token'] // or $_GET[];
$me = $facebook->api('/me', 'get', $args);
print_r($me);
So what that does then is say to FB I know the request is coming from a different server, but I have a valid token, please accept this sacrifice to mark zuckerberg and let me do things. It will accept and you're free to do as you please :)