publish_stream message visibility to everyone - facebook

I use Facebook PHP API to publish to profile's news feed:
$this->facebook->api('/me/feed', 'POST', array(
'message' => $msg,
'link' => 'http://'.$_SERVER['SERVER_NAME'],
'privacy' => array('value' => 'EVERYONE')
));
but this message is visible only to friends. I want it to be publicly visible to everyone! Even non-friends. How to do this ?

You, for security reasons, cannot override a user's choice on how your app posts messages. The best you can do is to change the default visibility setting of your app (https://developers.facebook.com/apps/{APPID}/auth) to Everyone, and then let the user change it to something else when authorizing your app. The user also has a chance to change the setting in own settings at any time later.

Related

Webtechnick CakePHP-Facebook-Plugin permissions not working

I'm using the Webtechnick CakePHP-Facebook-Plugin in order to log my users into my CakePHP application, I need to get their user_relationship, user_relationship_details, user_religion_politics and email.
Im using something kike this to invoke the login button
echo $this->Facebook->login(array('perms' => 'email,user_religion_politics,user_relationships,user_relationship_details', 'redirect' => array('controller' => 'users', 'action' => 'facebook'), 'label' => __('<span class="icon-facebook-sign"></span> Login with facebook',true),'id' => 'facebook_btn' ));
And also in facebook on "App details" in the "Configure App Center Permissions" section I'm adding the permissions too, but its not working, when a user login into the app facebook is still requesting the default perms (public profile, friends list and email).
I solved it, It seems that I was missing $options parameter on my init function.
So I changed the call in my default.ctp file
from
$this->Facebook->init();
to
$this->Facebook->init(array('perms' => 'email,user_religion_politics,user_relationships,user_relationship_details'));
I solved it, It seems that I was missing $options parameter on my init function.
So I changed the call in my default.ctp file
from
$this->Facebook->init();
to
$this->Facebook->init(array('perms' => 'email,user_religion_politics,user_relationships,user_relationship_details'));

how to post facebook user wall/ page status by a single user only no app install for other users

I am working on a site and i need to post page links from that site to a special user wall or page if something is published on it which means i only need one user to post that question.
the problem which i am facing is access token since i am not trying to show facebook login page in front of website traffic. its not like sharing on user wall we are basically trying to post status on a page automatically so any help for this problem will be appreciated.
i am using the following code which seems to work fine as long as the access token for the page is valid but i need to make something permanent so that i can add all the info in the php code hardcoded and it work for some weeks at-least without changing the api key or token
$appid = 'code';
$appsecret = 'code';
$wall= $pageId = 'code';
$token='page token';
$facebook = new Facebook(array('appId' => $appid, 'secret' => $appsecret, 'cookie' => true));
$params=array( 'message' => $msg,'name' => $title, 'caption' => $title, 'link' =>$uri,'description' => $desc, 'picture' => $pic, 'access_token' => $token,'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) );
$result = $facebook->api($wall.'/feed/','post',$params);
if i make token from the graph api debug page then it works fine but after some time i got the message "OAuthException: An active access token must be used to query information about the current user."
i am really desperate to find something solid for it.
thank you
You can write a backend script (maybe a cron job using the FB PHP-SDK) that runs as the special user and makes the desired FB api calls. For this, you will want to use a long-lived access token, which needs to be renewed every 60 days. You might also try your FB api calls using an App Access Token, which do not expire but also do not support all FB publishing and other operations.
To post to someones wall (or perform any action with the open graph) you must be authenticated with facebook as somebody in their graph or an application that they have granted permission to.
You should look at the permissions that can be set using the oauth scope attribute...
https://developers.facebook.com/docs/reference/dialogs/oauth/
To me it looks like they will need to grant your application publish_stream if you want to write to their friends walls as well as the user that you are authenticated as.
https://developers.facebook.com/docs/reference/login/extended-permissions/

Multiple posters on page

I have a question, It might be found somewhere but I couldnt find a thread for it so if there is one, please post the link.
I admin a page that is a group of several other business areas. I want to post on one page with different icons and names, can that be done? Like different admins but administered by one person/account?
Possible?
What you are going to want to do is use a "Page access_token". To get this you will have to create an application and grant it the manage_pages permission.
You should see in the Authentication Documentation a section called "Page Login".
You can grant your application the manage_pages permission by going to this URL:
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages&response_type=token
Don't forget to substitute YOUR_APP_ID and YOUR_URL with the correct values for you application and URL. (the URL can be any URL - it is where Facebook will send you after you close the Dialog). You will see a dialog that looks something like this :
Once you have the correct permission, you'll want to make a call to this URL :
https://graph.facebook.com/me/accounts?access_token=TOKEN_FROM_ABOVE
You will get a response similar to :
As you can see from the image, you will receive a list of all the pages that the user administers along with an access_token for each page.
You use this access_token to make posts on behalf of the page. Since you have not stated what programming language you are using I will give an example in php.
In php, posting to the page would look something like this :
$facebook->setAccessToken(ACCESS_TOKEN_YOU_RETRIEVED_EARLIER);
$attachment = array('message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$result = $facebook->api('/PAGE_ID/','post',$attachment);
Hope this helps!
Happy coding!

Directing users to facebook login page without asking for permissions

I'm trying to redirect users to the facebook login page then back to my app without the Log In to app page displaying. Is this possible?
I've looked into the "next" parameter which is automatically generated by the PHP-SDK but cannot seem to change it.
Is there anyway to do what I'm looking for? I want to make sure users are logged in in order to check to see if they have authed my app but do not want them to if they are not already.
Thanks for any help!
No, i don't think it is possible to modify the next parameter. The only place where i saw the next parameter(in the PHP SDK) is in the getLogoutUrl() function, as seen in the source of the base_facebook.php. And that parameter defines which url to go, after logout.
For getLoginUrl() in the base_facebook.php file, we have
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
'client_id' => $this->getAppId(),
'redirect_uri' => $currentUrl, // possibly overwritten
'state' => $this->state),
$params));
as the last line in the function, which obviously means that the oauth-dialog will be shown, no matter what you try.
If your app is not on Facebook, then you can go for <fb:login-button>Login with Facebook</fb:login-button> in Javascript, and subsequently follow the example from this url. You'll see there that it's not possible to remove that dialog entirely, even if you don't ask for any permissions.
The Javascript SDK's FB.login() method will also bring up the auth dialog.
Hope this helps.
They have to accept permissions for the first time only. Facebook will never let you to get user's data without their knowledge/accept
If you are using php :
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true
));
//Facebook Authentication part
$user = $facebook->getUser();
if (!$user) {
// user is not logged on --> redirect to the login url
} else {
// user is logged on you can do what you want
}

Posting to Friends Wall

In the new PHP SDK is there any way to post to a friends wall?
I have seen several apps do it. Like apps that say "your friend asked you a question", and I'm not even a user of that app. Is there any way to do it?
I am using an FBML canvas. I already have all the users friends, just need to figure out how to post to the friends they select from the list.
Thanks
You can use the facebook api method below, this works with the 3.1.1 SDK:
$publishStream = $facebook->api("/$user/feed", 'post', array(
'message' => "Your Message",
'link' => 'http://example.com',
'picture' => '',
'name' => 'App Name',
'description'=> 'App description'
));
Just replace the $user variable with the user id of your friend.
Yes, as long as you have the publish_stream extended permission
Enables your application to post
content, comments, and likes to a
user's stream and to the streams of
the user's friends, without
prompting the user each time.
As far as publishing goes
http://developers.facebook.com/docs/api#publishing