Hi i\'m new to facebook sharing. I want to make a user log in using his uid and then store these for further uses
The primary purpose is to share links in the user\'
I suggest you start learning how Facebook Graph API works first.
Now to post on the user's wall (on his behalf) without him being logged-in, you need the following:
publish_stream
permission, NO NEED for the long-lived access token: Enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends. This is a superset publishing permission which also includes publish_actions. However, please note that Facebook recommends a user-initiated sharing model. Please read the Platform Policies to ensure you understand how to properly use this permission. Note, you do not need to request the publish_stream permission in order to use the Feed Dialog, the Requests Dialog or the Send Dialog.
Require the permission:
This can be done in multiple of ways:
Using the Login Plugin:
<div class="fb-login-button" data-show-faces="true" data-width="200" data-scope="publish_stream" data-max-rows="1"></div>
Server-side login (Redirect to the OAuth Dialog):
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID
&redirect_uri=YOUR_URL
&scope=publish_stream
&state=SOME_ARBITRARY_BUT_UNIQUE_STRING
PHP-SDK:
$loginUrl = $facebook->getLoginUrl(array("scope"=>"publish_stream"));
JS-SDK through the FB.login method:
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
FB.logout(function(response) {
console.log('Logged out.');
});
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'publish_stream'});
Publishing:
$USER_ID = "XXXXXXXX"; // Connected once to your APP and not necessary logged-in at the moment
$args = array(
'message' => 'Hello from app',
'link' => 'http://www.masteringapi.com/',
'caption' => 'Visit MasteringAPI.com For Facebook API Tutorials!'
);
$post_id = $facebook->api("/$USER_ID/feed", "post", $args);
Note:
While it's possible to post without the user's presence always remember Facebook recommends a user-initiated sharing model