I have a new web app in development mode, and am trying to post to a users wall using something like this:
<fb:login-button scope="publish_pages" autologoutlink="true" onlogin="OnRequestPermission();">
</fb:login-button>
...
var params = {};
params['message'] = 'Message';
params['name'] = 'Name';
params['description'] = 'Description';
params['link'] = 'http://www.example.com';
params['picture'] = 'http://example.com/example.png';
params['caption'] = 'Caption';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
console.log(response.error);
} else {
alert('Published to stream - you might want to delete it now!');
}
});
I am testing this after a successful login using the FB account defined in that app as admin, but am getting an OAuthException error:
"(#200) The user hasn't authorized the application to perform the action"
Do I need to send the app through review to get additional access even though we are in testing? Is there something else I missed here?
Thanks
You are using the wrong permission, you would need publish_actions to post to the user wall. publish_pages is for posting to a Page you own. You do not need to go through the review process for testing, all permissions work without review for users with a role in the App.
Related
How can I gett the facebook username of a user via appcelerator facebook login
var fb = require('facebook');
fb.appid = "153xx364563xxxx";
fb.permissions = ['publish_stream']; // Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(e) {
if (e.success) {
Ti.API.info("Success " + JSON.stringify(e));
alert('Logged In');
} else if (e.error) {
alert(e.error);
} else if (e.cancelled) {
alert("Canceled");
}
});
all I get is the id and name
Success {"success":true,"code":0,"data":"{\"name\":\"John Smith\",\"id\":\"10111182454657222\"}","uid":"10111182454657222","cancelled":false,"bubbles":true,"type":"login","source":{"id":"facebook","appid":"153xx364563xxxx","forceDialogAuth":true},"cancelBubble":false}
The publish_stream permission is deprecated since many years, and there is no way to get the username anymore. The replacement for publish_stream would be publish_actions, but you only need that permission to post to the user wall.
Changelog for v2.0:
/me/username is no longer available.
Source: https://developers.facebook.com/docs/apps/changelog#v2_0
You do not need the username anyway, just use the (App Scoped) ID to identify returning users.
Following the standard example from the docs, but it's not working.
Funny thing is that if I do Ti.API.info(fb.getPermissions()), publish actions is listed.
Here's the output from that line:
[INFO] : permissions=
[INFO] : publish_actions,status_update,publish_stream,read_stream,manage_pages
Code:
var fb = require('facebook');
fb.appid = '1234567';
fb.permissions = ['publish_actions', 'status_update', 'publish_stream', 'read_stream','manage_pages']; // Permissions your app needs
fb.authorize();
fb.forceDialogAuth = true;
var data = {
caption: 'This is a test',
picture: blob
};
fb.requestWithGraphPath('me/photos', data, 'POST', function(e){
if (e.success) {
alert("Publish is ok");
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});
publish_stream is deprecated since years, and competely senseless if you use publish_actions anyway.
That being said, the error message means that the authorization process was not successful. If you are trying as Admin of the Facebook App, you should debug your Access Token after authorization, and make sure that you get asked for the permissions in the process.
If you are NOT trying with an Admin/Developer/Tester of the App, it is most likely because the permissions need to get approved in the Login Review first: https://developers.facebook.com/docs/facebook-login/review
Im trying to build a 'cheer action' for my app. It is a game in iPhone, so I want to post a 'welcome message' in the users wall (I will need 'public_stream' permission) and then invite his friends to visit my webpage.
Here my question.. I authenticate the user using:
_url = "http://www.facebook.com/dialog/oauth/?client_id=" + app_id + "&redirect_uri=" + app_net_folder + auth_response_uri + "&state=" + session_id;
I get response in my uri, and then I get the access_token, user_id, etc.
Then I post a message in his wall in this way:
_url = "https://www.facebook.com/dialog/apprequests?app_id=" + app_id;
_url += "&message=" + string_ToUrl(String_ToHTML(request_msg));
Now I want to invite his friends (using a multi friend list dialog). To do it, I can only use JavaScript FB.ui. In this way:
FB.init({appId : app_id, logging : false, frictionlessRequests: true, oauth : true});
FB.ui({method: 'apprequests', message: msg, title: title}, requestCallback);
When I do it, a window is opened asking me again for the user's login.. but my user has been already authenthicated. So I dont know how to say to FB in JavaScript that my user has been alredy authenthicated! (I even have the access_token, but I don't know how to use it in JavaScript functions).
Someone knows what am I doing wrong? or how to do those two actions asking just one time for the user's login?
Thanks!!
if you are already log in, you can get login user id using below code
var userId = FB.Facebook.apiClient.get_session().uid;
if(userId > 0 || userId != '')
{
alert('user is already log in');
}
hope it's helpful to you
I am using Nick Baker's (webtechnick) CakePHP / Facebook plugin which is awesome and works great, however I have a question that I can't seem to even come close to answer for.
How would I bypass the use of a share button and share directly through an action?
For instance, I make a post through my site and the post adds to the DB as it should, it also shoots a post to the logged in users Twitter account through the action. How can I also have this action handle sharing it to my FB account (connection has already been made).? I tried the first thing I think anyone would obviously try $this->Facebook->share() directly in the action, too no avail...
Any thoughts or solutions would be of great help...
UPDATE AFTER ANSWER
Thx for the help spooney. I voted your answer up because you are 100% spot on from what I can tell. I am loading the JS SDK.
function init($options = null, $reload = true) {
if (empty($options)) {
$options = array();
}
if ($appId = FacebookInfo::getConfig('appId')) {
$session = json_encode($this->Session->read('FB.Session'));
if ($reload) {
$callback = "FB.Event.subscribe('auth.login',function(){window.location.reload()});";
} else {
$callback = "if(typeof(facebookReady)=='function'){facebookReady()}";
}
$callback .= "FB.Event.subscribe('auth.logout',function() {window.location = '/bastards/users/logout'});";
$init = '<div id="fb-root"></div>';
$init .= $this->Html->scriptBlock(
<<<JS
window.fbAsyncInit = function() {
FB.init({
appId : '{$appId}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true // use Oauth
});
{$callback}
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/{$this->locale}/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
JS
, $options);
return $init;
} else {
return "<span class='error'>No Facebook configuration detected. Please add the facebook configuration file to your config folder.</span>";
}
}
I have no problem pulling in the user information and working with all that. I have accomplished posting to FB from my site, but it was only through a link, using FB.ui...
<br><font style="color:#FFF; text-decoration:none;padding-left:27px;">post to wall</font><br>
<script>
function publishStory() {
FB.ui({
method: 'feed',
name: 'message name',
caption: 'message caption ',
description: 'description goes here',
link: 'the url current page',
picture: 'if you want to add an image'
},
function(response) {
console.log('publishStory response: ', response);
});
return false;
}
</script>
I have tried replacing the code above with...
<br><font style="color:#FFF; text-decoration:none;padding-left:27px;">post to wall</font><br>
<script>
function publishStory() {
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
</script>
But it errors everytime.
I should also throw in there that the post on the users FB wall isn't really coming from the site persay, it's a post from the user on their own wall basically stating, "I made a post on ladala.com, you should go check it out at ."
So now I'm at the point that I need to figure out how to run FB.ui through the action that submits the post.
Based on our conversation, I figured I would just put a more complete description in an answer.
You can fire a share call using the JavaScript SDK.
First, you would need to load the JavaScript SDK as described in the Loading section of https://developers.facebook.com/docs/reference/javascript/.
Once loaded into your page, the two calls you want to look at are FB.getLoginStatus, and FB.api. FB.getLoginStatus will give you back a response telling you if the user is logged in to facebook, and if they have approved your application. This link will describe the functionality of getLoginStatus, but in short, you need to check for response.connected(and then possibly do another call to confirm a user's permissions, if required).
If the user is logged in and has approved your app, you can then attempt to make an API call using FB.api. Keep in mind to do this, you will likely need the user to have allowed the publish_stream permission.
Your code would look something like this:
//Do FB initialization
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
//Post was successful
}
});
}
});
This can be triggered any way you want. On page load, on click, on completion of some other event, etc.
Keep in mind this is just one way to implement this. Also, if you are trying to share something with your FB application, and it is not working, you should confirm that you have all the permissions required to do so.
with help of docs, tutorials and this forum I managed to create an event for the logged in user on his profile or page, as he chooses.
I also figured, that for inviting friends I'd have to use events.invite.
Since I don't want to invite all of the user's friends but several, I implemented a request, which as a result returns the selected friend's ids.
Those I'm using for the events.invite call. I get bool 1 as result (which means, the invitation was sent successfully) but there is no invitation to be seen in friends bookmarks or event page.
Everything besides invitation is working.
3 questions come up:
1) Does events.invite need additional permission besides 'create_event' ?
I tryed events.invite independently and couldn't get results either...
2) Is there a better way to select friends before sending invitation? I do not want app request being sent out each time an event is created.
3) If 2 is negative, how can the app request (and bookmark) be subdued or removed from friend's profile? Deleting the request via API obviously doesn't remove the message in application requests.
* in main script: [javascript]
function sendRequest() {
FB.ui({
method: 'apprequests',
message: 'Test',
title: 'event invitation for up to 20 friends',
max_recipients: 20,
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids.join(',');
var invite_ids = new Ajax.Request('/facebook/handle_invitation.php', {
onSuccess: function(test) { alert('Done!'); },
method: 'post',
parameters: {tid: '<?php echo $target_id; ?>',
request_ids: requests,
eid:'<?php echo $event_id; ?>',
token: '<?php echo $access_token; ?>'}
});
} else {
alert('canceled');
}
});
return false;
}
* and in 'handle_invitation.php' (called from request response):
if( isset($_POST['request_ids']) && isset($_POST['uid']) ) {
$target_id = $_POST['tid'];
$event_id = $_POST['eid'];
$access_token = $_POST['token'];
$requests = explode(',',$_POST['request_ids']);
foreach($requests as $request_id) {
$request_data = $fb->api("/$request_id?$access_token");
$invite_id[] = $request_data['to']['id'];
$fb->api("/$request_id?$access_token", "DELETE");
}
//invite friends to my event
$return = $fb->api(array(
'method' => 'events.invite',
'eid' => $event_id,
'uids' => $invite_id,
'personal_message' =>"Einladung zu meinem Event"
));
}
Hope this was not too detailed. I'd appreciate any help, since after days of reading and experimenting I'm finally stuck at this point. Thx!
The graph api now allows you to invite users by user_id. See http://developers.facebook.com/docs/reference/api/event/
invited
Create
You can invite users to an event by issuing an HTTP POST to /EVENT_ID/invited/USER_ID. You can invite multiple users by issuing an HTTP POST to /EVENT_ID/invited?users=USER_ID1,USER_ID2,USER_ID3. Both of these require the create_event permission and return true if the invite is successful.
I don't think "sent event invitation" is in the GRAPH API yet. It is available in REST API but its not working as we expect.
I found some known issues and limitations with facebook events. Please see the links below from the official documentation on facebook
Limitation on number of people that could be invited to an event.
http://www.facebook.com/help/?faq=12576#!/help/?faq=202545109787461
Event members are not receiving messages I have sent.
http://www.facebook.com/help/?page=786#!/help/?faq=188295427885002