Public posting on fan page with facebook graph api - php

I made a script in which automatically put in a fan page on facebook, the script works, but the post is only visible to the user who posted (which is the admin of the fan page), the login'm asking permissions below:
$loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
And I'm posting with the following code:
$args = array(
'access_token' => $page_info['access_token'],
'link' => 'http://www.sitelink.com.br/alguma-coisa',
'method' => 'post'
);
$facebook->api("/99999999999/feed","post",$args);
Does anyone know if the login I have to ask some permission to appear as the most public posts?
I have to configure something else in there in the facebook app developers?

Related

Facebook app posting to page successfully, but posts are not visible to non-developers. Do I really have to review for an app with 1 user?

I have setup a facebook app to post images / videos to one particular fan page. It requests 'publish_actions' and 'manage_pages permissions. It is in developer mode and I have no intention to expand the functionality beyond posting to this single facebook page.
The code works correctly, it posts to the correct page and everything looks good whilst logged into the developer account / page admin (same account). But other facebook users cannot see the posts that have been made via the app. I was under the impression that apps didn't need to go through the review process for internal apps such as these?
Heres a quick stripped down version of the code for posting to the page:
FacebookSession::setDefaultApplication($settings['app_id'], $settings['secret']);
//This is user access_token not the pages.
$session = new FacebookSession( $settings['access_token'] );
$pageTokenResponse = (new FacebookRequest(
$session
, 'GET', '/' . $settings['page_id']
, array( 'fields' => 'access_token' )
))->execute()->getGraphObject(GraphPage::className());
//Retrieved Page Token
$pageToken = $pageTokenResponse->getProperty("access_token");
uploadUrlToFacebook($imgurl, $item->get_title(), $session, $pageToken, $settings['page_id']);
function uploadUrlToFacebook($url, $title, $session, $pageToken, $pageId){
$request = new FacebookRequest(
$session,
'POST',
"/$pageId/photos",
array (
'access_token' => $pageToken
,'url' => $url
,'message' => $title
)
);
$response = $request->execute();
}
I'm sure there is a stupid error either somewhere in the code or my apps setup but why can I see the posts but nobody else can ?
Turns out I had already selected some items for review before I properly understood the process so I ended up in a state of not being able to make the app live as I had pending review items. I deleted the permissions from the review queue, made the app live and all is good.
I think while authenticating Fb App you given "only me" visibility for Publish Actions.
go to https://www.facebook.com/settings?tab=applications
Select your App .
Then Check this . "App visibility and post audience"

Facebook: message posted with PHP SDK not sent to twitter

I an facing an issue with the Facebook SDK POST action when posting a very basic message on my page which is linked to my Twitter account. I have tried to solve the issue by myself using Google and StackOverflow, but I didn't manage to find a fix.
The issue is the following:
When I post a message with the SDK:
It appears in the page and is visibe by myself
It appears in the page also for other Facebook user
It appears in the Facebook Feed
but the message is not transmitted to my Twitter account
When it post something "manually" it is correctly sent to my Twitter account. The issue only appears when using the SDK. Hereafter you can find my code and the context of my request:
I am using a PHP script on my personal desktop (WAMP server).
The attachement is very very basic: 'message' => "Hello dear followers!"
The application used to post is not in sandbox mode.
Your app detail page has not yet been submitted for review.
The message appears as public on the page and is indeed visible by other users.
When I post manually the exact same message, it is correctly sent to Twitter.
Can you help me with this issue? Many thanks and all the best.
$appid = *(hidden)*;
$appsecret = *(hidden)*;
$pageId= *(hidden)*;
$facebook = new Facebook(array('appId' => $appid,'secret' => $appsecret,'cookie' => false));
$user = $facebook->getUser();
if($user){
try{
$page_info = $facebook->api("/$pageId?fields=access_token");
if (!empty($page_info['access_token'])){
$attachment = array(
'access_token' => $page_info['access_token'],
'message' => "Hello dear followers!",
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$status = $facebook->api("/$pageId/feed", "post", $attachment);
}
}
}
The issue appears because of the special action item:
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
Removing this specificity the message is transmitted to Twitter, successfully.

Post to facebook page on behalf of user who is not a page admin

We are trying to build a facebook application that posts a message from a user to a facebook business page (which the user is NOT an admin of.) We need the post to be from the USER, not the page or the page admin. We are using the facebook PHP SDK and so far have accomplished getting the user's message to post to their own feed. (Using an App Access Token.) Though when we try to post the message to the facebook page (not owned by the user) we get this error:
Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in
Is it possible to post to a facebook page, not owned by the user on behalf of the user? We are admins on the facebook page, but if we post using the Page Access Token then the post is no longer authored by the user, but instead the facebook page or page admin.
Here is a snippet of our code to see how we're going about this:
Posting to user's feed as user (works)
$fbpage = "/$fbid/feed";
$attachment = array(
'message' => $msg,'from' => array('name' => $name,'id' => $fbid));
$result = $facebook->api('/'.$fbpage.'?access_token='.$accesstoken, 'post', $attachment);
Posting to facebook page as user (doesn't work)
$fbpage = "/johnsjoint/feed";
$attachment = array('message' => $msg,'from' => array('name' => $name,'id' => $fbid));
$result = $facebook->api('/'.$fbpage.'?access_token='.$accesstoken, 'post', $attachment);
After a lot of research, it appears that this isn't possible. If anyone knows otherwise, please post here.
Not sure if its the exact same issue, but this might shed a light over your problem. See
"Posting to Facebook fan page feed as user through PHP SDK"

Facebook Graph Api posting on friends wall

I'm having a problem when trying to post a link to a friends wall using the Facebook graph from my application.
I am currently using the Facebook SDK for PHP, I have no problems posting to the wall of the user that's logged in but cannot post to friends of the logged in user.
I have requested the extended permission "publish_stream" and here is the code am I using:
$args = array('message' => $message,
'link' => 'google.com',
'name' => 'Test!',
'caption' => 'Please click on the link',
'description' => 'description');
$result = $facebook->api("/$friendId/feed", 'POST', $args );
$friendId has the facebook id of the friend of the logged in user, any help would be much appreciated.
A quick scan of the FB API reference shows that you can set the to key value pair in this operation to
mention or target a user in this post

programmatically login to facebook and post to page (wall)

I have a website, and I need it to post status updates to a Facebook Page from time to time.
Using my personal Facebook account, I created an App, and a Page. So far, I've been able to programmatically post to my Page's Wall, by adding this code to my website:
include_once "lib/facebook/src/facebook.php";
$facebook = new Facebook(array('appId' => 'APP_ID_HERE', 'secret' => 'APP_SECRET_HERE'));
if($facebook->getUser()) {
try {
$ret_obj = $facebook->api('/FACEBOOK_PAGE_ID_HERE/feed', 'POST', array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!',
'access_token' => 'FACEBOOK_PAGE_ACCESS_TOKEN_HERE'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
} catch(FacebookApiException $e) {
// user logged out (has user_id, but invalid access token)
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
echo 'Please login.';
}
echo '<br />logout';
} else {
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
echo 'Please login.';
}
So I just open my website, click "Please login", login as myself. Once I'm logged it, it will now be able to post the status update to the Facebook Page.
Obviously, the problem here is that I need to be logged in for it to be able to post. If other users will try to login with their user accounts, my website cannot post status updates to the Facebook Page because I am the only Admin for the app/Page.
My question is, is there a way for me to programmatically log myself into Facebook so I can do these status updates to my Page automatically?
Sorry, total noob here to Facebook development.
Seems like you need to update status while you are offline from facebook. To do this you need to get the offline access permission of the app user and you need to have a "infinite" token for facebook app to access the APIs, so that your program can update anytime you want with out logging into facebook.
You may get something you want here
http://developers.facebook.com/docs/authentication/
I'm a little late to the party here, but I thought I'd post my gist example for how to do something very similar. I added some functionality to fbconsole to make it easy to programmatically login with fbconsole.automatically_authenticate to make it much easier to access this information in a systematic way. This addition has not yet been incorporated into the master branch of fbconsole (it was just posted this morning), but it is available here in the meantime for those that are interested.
This is what I use to do,
// = SET WALL DATA HERE ===============
$attachment = array(
'access_token' => 'My Access token here',
'message' => '',
'name' => 'My Wall Post Header/Title Here',
'caption' => 'Small caption here',
'link' => 'http://www.mywebsite.org',
'description' => 'Wall Post Details Here',
'picture' => "http://www.mywebsite.org/images/logo.gif",
);
// =POST ON FACEBOOK WALL ==========================
$this->facebook->api('/me/feed', 'POST', $attachment);
, $attachment);
So include your Facebook API, Get your Facebook Access token, SET data for your wall post and call for facebook api with me/feed method.
This will make a wall post on your wall without asking for login.
make sure you are using correct Access Token.

Categories