Facebook Graph API - Unable to post feed by app name - facebook

I am trying to make an app that has permission to post on user's wall. I have got the publish_stream rights from the user as well as offline access just to make sure. However now when I try to post on the app's subscribers wall using:
$status = $facebook->api("/$user_id/feed", 'POST', array('message' => "$msg"));
However when I do that then instead of posting on subscriber's wall from app it posts from the subscriber's name.
For example, let's say my app name is MyApp and I have a subscriber name Sub1. If, from my interface, I try to post a message 'Test message', it posts on Sub1's wall not by name of MyApp but instead the user himself. Can anyone tell me what might be wrong?

Related

App in facebook Require Approval?

Scenario is like this:
I have created an app in facebook say myApp.
I have integrated facebook login in my website say mywebsite.com.
I am intended to fetch user's "education_history" ,"work_history" ,"books" , "music".
I am not asking permissions for writing anything on user's facebook wall.
Here the problem.
I am able to fetch required information from facebook only when I logged in ( myapp created on my account only ) but when someone else try to login to mywebsite.com through facebook then I get only his public profile nothing else.
Why is it so ? What I am missing. All permissions are correct.
Thanks for help
EDITED :
Code for login URl :
// Return facebook or linkedIn login url
public function loginurl(){
// It is facebook
$login_url_params = array(
'scope' => 'email,user_actions.book,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_education_history,user_groups,user_hometown,user_interests,user_likes,user_website,user_work_history',
'redirect_uri' => 'http://localhost/users/store/fb/'
);
$login_url = $this->facebook->getLoginUrl($login_url_params);
echo "<a href=" . $login_url.'>Login</a>';
}
You should get a warning when you authorize some specific permissions as App Admin/Developer, telling you to review them:
Apps requesting more than public_profile, email and the user_friends permission must be reviewed by Facebook before those permissions can be requested from people
Here´s more information about the review process: https://developers.facebook.com/docs/apps/review
Localhost will only work for you, but not for other users. Except you are trying with another user on your computer, of course.

Facebook access token for post message in timeline

I am trying to do something like this. Lets say a user used FB Connect for registration in our site, so I can get the "uid" of facebook and I can store in DB. Now what I want each time that user will visit a store details page or item details page I will post that store/item image with link, photo, description etc to FB timeline.
Something like this:
$post_id = $facebook->api('/me/feed/', 'post', array(
'message' => $products_name, // item name
'link' => 'http://www.blabla.com/item/myshoes', // item url
'picture' => $fb_img_src, // item image
'caption' => $products_name, // item name for caption
'description' => $products_description // item description
));
} catch (FacebookApiException $e) {
$user = null;
}
This process works fine if user logged in to FB by using our FB app. But as I said I want to post if they not even logged in by using their facebook "uid".
Is it possible to authenticate that user depending on facebook "uid"?
Thanks in advance! Any clue/help will be appreciated!
I strongly believe that posting anything to user's Facebook without their's consent or even their action will surely and quickly encourage them to leave your site forever. Do not do this.
Anyway - to answer your question:
Yes, it is possible to get access to user's Facebook and "do stuff", especially when a user is logged in both on Facebook and on your site. You just need to obtain user's access token (read about it in the docs), and make sure the users grants your app all aproppriate permissions. There are also access tokens that can be used offline (user is not even online), but I'm not going to discuss it here.
One way to obtains user's access token is to redirect the user to FB login url providing your APP_ID (as described in FB developers docs). FB will then redirect the user to your Fb-login URL with access code/access token, which enables you to do something like posting to users timeline.
Of course actions that you can take are limited according to permissions said user has granted for your app. And I have to remind you - it's a thin ice you're stepping on.

Put a hash tag automatically to publish_stream posts via Facebook APP

I would like to put a hash tag (like # my_app) on users posts via Facebook API. Will this be Terms violation?
Sample Code:
<?php
$message = $_POST('message');
$facebook->api('me/feed', array('message' => $message . ' #my_app'));
There is the following description in the terms, is it no problem as long as we notify users before?
(https://developers.facebook.com/policy/#integration)
If a user grants you a publishing permission, actions you take on the user's behalf must be expected by the user and consistent with the user's actions within your app.

Posting on facebook friend's wall via facebook app doesnt work

I want to post on my facebook friends wall using my facebook app. I have already set the sufficient permissions like publish_stream, offline_access for it and I am using it's Graph API with PHP but it post to only those who are either the developer of the app or the administrator of the app. I dont know where i am doing the mistake. However one of my friend has successfully done it through objective c(iphone) code. I checked his code he was doing the same way as I am doing. Please help me over it. Here is my code and I am using facebook sdk 3.0 -:
if(isset($_POST['submit'])) {
$sendTo = $_POST['friend'];
$link = $_POST['link'];
$message = $_POST['message'];
$attachment = array('message' => $message, 'link' => $link );
if($result = $facebook->api("/$sendTo/feed/",'post', $attachment))
{
$feedbackMessage = "Message sent to friend $sendTo";
}
else
{
$feedbackMessage = "Oops something went wrong";
}
}
First of all, I would suggest that you will take a look at the recent update to facebook developers roadmap:
https://developers.facebook.com/roadmap/
February 2013 Breaking Change:
"Removing ability to post to friends walls via Graph API
We will remove the ability to post to a user's friends' walls via the Graph API. Specifically, posts against [user_id]/feed where [user_id] is different from the session user, or stream.publish calls where the target_id user is different from the session user, will fail. If you want to allow people to post to their friends' timelines, invoke the feed dialog. Stories that include friends via user mentions tagging or action tagging will show up on the friend’s timeline (assuming the friend approves the tag). For more info, see this blog post."
As mentioned by CBroe, the fact that only app administrators/developers can post might be related to the sandbox settings.
Anyway, the api should return a detailed error.

Check if user can write on a friend's Wall

If there any way to check in PHP SDK if user can write on specific friend's Wall?
Example:
if ($facebook_can_write_to->'123456789') echo "You can write on this friend's Wall";
Using the FQL table (http://developers.facebook.com/docs/reference/fql/user/) you can check to see if the current user can post to a friends wall by loading up the friend's user information specifically the can_post field.
can_post bool Whether or not the viewer can post to the user's Wall.
According to the documentation you can post on a user friends wall if that user granted you the *publish_stream* permission:
publish_stream
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends.
There are some cases in which you won't be able to do so, for example if some user blocked your application then I guess it will fail if you try, so you should just check the response you get back from facebook for the api request and see if it worked or not.
Edit
As far as I'm aware you can not ask the api (nor via fql) "can my application post to this users wall", you can only ask "have this user granted my application the publish_stream permission".
If I understand what you want, I might have kind of a solution for you though.
I say show the user the option to post on a friends wall.
When the user chooses this option try to post on the friends wall (and I assume you are using ajax for that call), if it fails return some kind of code, then in the client side check for that code, if it returns use the javascript sdk to open a dialog.
You have two choices for dialogs, you can use the Feed Dialog like this:
var obj = {
method: 'feed',
to: "FRIEND_ID",
name: 'A message',
caption: 'Just trying something',
description: 'This is how to post on a friends wall'
};
FB.ui(obj, function(response) { console.log(response); });
Or you can use the Send Dialog:
FB.ui({
method: 'send',
to: "FRIEND_ID",
name: 'A message',
link: 'LINK_URL',
});
With this one though you have to post a link, I'm not sure if that works for you. After you tried and failed for a user you can save that data and use it later.