Titanium: Facebook API: (#200) Requires extended permission: publish_actions - facebook

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

Related

appcelerator facebook get username

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.

How to post on wall when app is in development mode?

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.

Meteor Facebook login (Meteor.loginWithFacebook) issue extracting public profile, email and user_friends

Trying to get Meteor Facebook login to work. It functions fully in that it uses Facebook API and requests the correct permissions from the users account and then logs in successfully.
The problem is it doesn't save the permission requested information even though its been approved and only the basic name and ID are available in Meteor.user().services.facebook. Is this code not working because it's not saving the users details on login? I can't find a resource that details how to save or extract the other data.
Simply trying to console log the data to see that it's been extracted out of the Facebook user account on log in.
Within Meteor.isClient code:
Template.login.events({
'click #facebook-login': function(event) {
Meteor.loginWithFacebook({ requestPermissions: ['email', 'public_profile', 'user_friends', 'user_likes']}, function(err){
if (err) {
throw new Meteor.Error("Facebook login failed");
}
console.log(Meteor.user().services.facebook.name);
console.log(Meteor.user().services.facebook.id);
console.log(Meteor.user().services.facebook.email);
console.log(Meteor.user().services.facebook.gender);
});
},
'click #logout': function(event) {
Meteor.logout(function(err){
if (err) {
throw new Meteor.Error("Logout failed");
}
});
}
The config code:
ServiceConfiguration.configurations.remove({
service: 'facebook'
});
ServiceConfiguration.configurations.insert({
service: 'facebook',
appId: 'correctAppID',
secret: 'CorrectSecret'
});
For Facebook v2.4 API after you have requested for certain permissions you can then access them by making a graph API call and requesting them with a valid auth token. The code is as follows:
if (user.hasOwnProperty('services') && user.services.hasOwnProperty('facebook') ) {
var result = Meteor.http.get('https://graph.facebook.com/v2.4/' + user.services.facebook.id + '?access_token=' + user.services.facebook.accessToken + '&fields=first_name, last_name, birthday, email, gender, location, link, friends');
console.log(result.data.first_name);
console.log(result.data.last_name);
console.log(result.data.birthday);
console.log(result.data.email);
console.log(result.data.gender);
console.log(result.data.location);
console.log(result.data.link);
console.log(result.data.friends);
}

Cakephp Facebook Plugin - Sharing through an action

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.

Facebook API SDK revoke access

How can I allow a user to revoke access to my application using their API service, SDK. http://developers.facebook.com/docs/sdks/
Looking at the documentation I can't find anything about revoking the access.
For the FB JavaScript SDK:
FB.api('/me/permissions', 'delete', function(response) {
console.log(response); // true
});
in the graph API for the user object you can issue an HTTP DELETE request to /PROFILE_ID/permissions to revoke authorization for an app.
from the official documentation (developers.facebook.com/docs/reference/api/user/):
You can de-authorize an application or revoke a specific extended
permissions on behalf of a user by issuing an HTTP DELETE request to
PROFILE_ID/permissions with a user access_token for that app.
Parameter Description Type Required permission The permission you
wish to revoke. If you don't specify a permission then this will
de-authorize the application completely. string no You get the
following result.
Description Type True if the delete succeeded and error
otherwise. boolean
For anyone who would find this helpful, I was losing sleep and wrecking my brain for days trying to get this to work;
FB.api('/me/permissions', 'DELETE', function(response) {
if (response == true) {
window.top.location = 'logout-facebook.php';
} else {
alert('Error revoking app');
}
});
I finally got this to work when I observed that the "response" being returned was not a boolean but a JSON object.
The JSON object being returned was either;
{
success: "true"
}
OR
{
success: "false"
}
Following that, the correct code was;
FB.api('/me/permissions', 'DELETE', function(response) {
if (response.success == true) {
window.top.location = 'logout-facebook.php';
} else {
alert('Error revoking app');
}
});
Hope this helps someone!
With PHP SDK V 5
$DeletePermsUser = $fb->delete('/{user-id}/permissions/',[],$access_token);