FB.ui method 'permissions.request' deprecated? the response always be false for me - fb.ui

Here is my code:
FB.ui({method: "permissions.request", "perms": 'publish_stream', 'display': 'popup'}, function (response) {
console.log(response)
console.log(response.perms)
}, {scope: 'publish_stream'});
And the result is always 'false', does anyone know the reason?
Thanks

The permissions.request dialog is not (no longer?) in the spec for FB.ui:
https://developers.facebook.com/docs/reference/javascript/FB.ui/
It seems that the only way to ensure that a user is logged in and has the required permissions for an action is to use a combination of FB.login() with the proper permission scope, and then FB.api('/me/permissions') to query the Graph:
FB.login(function(response) {
if (response.status === 'connected') {
FB.api('/me/permissions', function(response) {
if (response.data && response.data[0] && response.data[0].publish_actions) {
console.log("You got'em!");
}
});
}
}, { scope: 'publish_actions' });

Related

for some reason my put route is not working in sequelize

this is my call
$.ajax({
url: "/api/user_data",
method: "PUT",
data: {
id: data.id,
level: newLevel,
point: addPoints
},
error: function(req, err) {
console.log(err)
}
}).then(result => {
console.log("user info updated");
console.log(result);
// window.location.replace("/members");
});
this is my route
app.put("/api/user_data", function(req, res) {
db.User.update(
{
points: req.body.points,
level: req.body.level,
},
{
where: {
id: req.body.id,
},
}
).then(function(result) {
res.json(result);
});
});
I am also getting an error saying "can't set headers after they are sent".
I had { force: true } set before and it was not working. When I set force: false the level would update but only after I logged out then logged back in. I'm not sure why that was happening at all but any help would be much appreciated.

Calling a Serenity service endpoint and react to success or failure on client-side

Until recently (one of the last full .net SF versions), I could call a Serenity service endpoint like below and react on success or failure. With current .net core (3.14.3) SF, somehow this seems not anymore to work.
I just get a dialog with the message content. I neither get "success" nor "error" alert box.
Question: How to do this with current SF 3.14.3.
Here my code from a project on full .net where this still works:
let bla1 = CountriesService.ImportCountriesFromRESTCountries(
{
},
response => {
alert('success');
let message = JSON.parse(bla1.responseText);
Q.notifySuccess(message, Q.text("Dialogs.Button.UpdateCountries.Import.Toast.Title"), options);
this.refresh();
},
{
blockUI: true,
onError: response => {
alert('error');
let errorcontent = JSON.parse(bla1.responseText);
let message = errorcontent["Error"]["Message"]
Q.alert(message);
this.refresh();
}
});
face same issue , i resolved this by
Q.serviceCall<Serenity.RetrieveResponse<any>>({
service: this.serviceUrl + '/Retrieve',
request: {
EntityId: this.value
} as Serenity.RetrieveRequest,
async: false,
onSuccess: (response) => {
this._selectedItem = response.Entity;
},
onError: (error) => {
console.log( error.Error);
}
});

Unit testing Sails/Waterline models with mocha/supertest: toJSON() issue

I'm setting up unit tests on my Sails application's models, controllers and services.
I stumbled upon a confusing issue, while testing my User model. Excerpt of User.js:
module.exports = {
attributes: {
username: {
type: 'string',
required: true
},
[... other attributes...] ,
isAdmin: {
type: 'boolean',
defaultsTo: false
},
toJSON: function() {
var obj = this.toObject();
// Don't send back the isAdmin attribute
delete obj.isAdmin;
delete obj.updatedAt;
return obj;
}
}
}
Following is my test.js, meant to be run with mocha. Note that I turned on the pluralize flag in blueprints config. Also, I use sails-ember-blueprints, in order to have Ember Data-compliant blueprints. So my request has to look like {user: {...}}.
// Require app factory
var Sails = require('sails/lib/app');
var assert = require('assert');
var request = require('supertest');
// Instantiate the Sails app instance we'll be using
var app = Sails();
var User;
before(function(done) {
// Lift Sails and store the app reference
app.lift({
globals: true,
// load almost everything but policies
loadHooks: ['moduleloader', 'userconfig', 'orm', 'http', 'controllers', 'services', 'request', 'responses', 'blueprints'],
}, function() {
User = app.models.user;
console.log('Sails lifted!');
done();
});
});
// After Function
after(function(done) {
app.lower(done);
});
describe.only('User', function() {
describe('.update()', function() {
it('should modify isAdmin attribute', function (done) {
User.findOneByUsername('skippy').exec(function(err, user) {
if(err) throw new Error('User not found');
user.isAdmin = false;
request(app.hooks.http.app)
.put('/users/' + user.id)
.send({user:user})
.expect(200)
.expect('Content-Type', /json/)
.end(function() {
User.findOneByUsername('skippy').exec(function(err, user) {
assert.equal(user.isAdmin, false);
done();
});
});
});
});
});
});
Before I set up a policy that will prevent write access on User.isAdmin, I expect my user.isAdmin attribute to be updated by this request.
Before running the test, my user's isAdmin flag is set to true. Running the test shows the flag isn't updated:
1) User .update() should modify isAdmin attribute:
Uncaught AssertionError: true == false
This is even more puzzling since the following QUnit test, run on client side, does update the isAdmin attribute, though it cannot tell if it was updated, since I remove isAdmin from the payload in User.toJSON().
var user;
module( "user", {
setup: function( assert ) {
stop(2000);
// Authenticate with user skippy
$.post('/auth/local', {identifier: 'skippy', password: 'Guru-Meditation!!'}, function (data) {
user = data.user;
}).always(QUnit.start);
}
, teardown: function( assert ) {
$.get('/logout', function(data) {
});
}
});
asyncTest("PUT /users with isAdmin attribute should modify it in the db and return the user", function () {
stop(1000);
user.isAdmin = true;
$.ajax({
url: '/users/' + user.id,
type: 'put',
data: {user: user},
success: function (data) {
console.log(data);
// I can not test isAdmin value here
equal(data.user.firstName, user.firstName, "first name should not be modified");
start();
},
error: function (reason) {
equal(typeof reason, 'object', 'reason for failure should be an object');
start();
}
});
});
In the mongoDB console:
> db.user.find({username: 'skippy'});
{ "_id" : ObjectId("541d9b451043c7f1d1fd565a"), "isAdmin" : false, ..., "username" : "skippy" }
Yet even more puzzling, is that commenting out delete obj.isAdmin in User.toJSON() makes the mocha test pass!
So, I wonder:
Is the toJSON() method on Waterline models only used for output filtering? Or does it have an effect on write operations such as update().
Might this issue be related to supertest? Since the jQuery.ajax() in my QUnit test does modify the isAdmin flag, it is quite strange that the supertest request does not.
Any suggestion really appreciated.

Post to facebook page as user

Am working on facebook graph API for posting on facebook page.I have a webpage where each users can login and share contents on a facebook page.Consider certain organizations,each organization has there own facebook page.From my website any user having facebook account can come and share their feedbacks about that organization and that feedback should be posted in the facebook page of the particular organization.
I need to implement this using facebook javascript api,but am getting an error
The user hasn't authorized the application to perform this action","type":"OAuthException","code":200
Here is my code:
FB.api('/page_id/feed', 'post',
{
message : "It's awesome ...",
name : 'Feedback',
to: '',
from: '',
description : 'Your description'
},
function(response) {
if (!response || response.error) {
//alert(JSON.stringify(response.error));
console.log(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
Please help
Thanks
Try this:
function login() {
FB.login(function (response) {
if (response.authResponse) {
// connected
postFeedBack();
} else {
// cancelled
}
}, { scope: 'publish_stream' });
}
function postFeedBack() {
FB.api('/page_id/feed', 'post', {
message: "My Feedback"
}, function (response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}

Post to facebook wall from phonegap android

Am trying to post to facebook wall from an android app written with phonegap. I do get the following error: message:(#200) the user hasn't authorized the application to perform this action type:OAuthException. So my question is How do i get the user to authorize my app so i can post to their wall. I use this code to login:
function login() {
FB.login(
function(response) {
if (response.session) {
alert('logged in');
} else {
alert('not logged in');
}
},
{ perms: 'publish_stream' }
);
}
and i try to post with the below code which throws an error.
function postToWall() {
var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { body: body }, function(response) {
if (!response || response.error) {
alert('Error occured ' + JSON.stringify(response.error));
} else {
alert('Post ID: ' + response);
}
});
}
Am using the phonegap facebook api from https://github.com/davejohnson/phonegap-plugin-facebook-connect and FB.ui does not work.
Thanks
Posting the same content throws errors so use a text type input for positioning content on Facebook, with post as the text type input:
function postdata()
{
var body = document.getElementById("post").value;
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error)
{
alert('Error occured');
}
else {
alert('Post ID: ' + response.id);
}
});
}
There are serious problems with that phonegap plugin right now. I'm really wishing it would be picked back up to fix them. One of the main issues is that oauth2 isn't supported and the plugin is using an older facebook sdk.