Facebook De-Authorization causes the api to fail - facebook

So my issue is when I use the facebook api everything seems to work fine till I revoke permissions on the app. Once I do that the api stops working. Here is the code:
if (socialMediaType == "facebook") {
//it always gets to this location even after the revoke happens
FB.getLoginStatus(function (response) {
//gets in here fine on page load and other instances,
//but if you hit permissions delete it never gets here
if (response.status === 'connected') {
if (!ConnectButtonClicked) {
FB.api("/me/permissions", "delete", $scope.fbRevokeCallBack);
} else { /*code here works fine*/ }
} else {
$scope.facebookLogin();
}
});
}
Is there something I am doing incorrectly with revoking permissions to the app?
Here is the call back:
scope.fbRevokeCallBack = function (Data) {
console.log('auth revoke', Data);
// check for a valid response
if (!Data || Data.error) {
$scope.$apply(function () {
$scope.fb.connectionError = true;
$scope.socialError = "error";
});
return;
}
if (Data) {
console.log("Success");
};
}
Success is hit and the app is revoked as expected, but when you go back to reconnect to facebook the api does nothing. No calls can be found in the networking tab and the call back is never hit.
Some information:
This is using the Facebook JSSDK
and this is used in AngularJS

Would $scope.$apply() help here?
if (socialMediaType == "facebook") {
//it always gets to this location even after the revoke happens
FB.getLoginStatus(function (response) {
//gets in here fine on page load and other instances,
//but if you hit permissions delete it never gets here
if (response.status === 'connected') {
if (!ConnectButtonClicked) {
FB.api("/me/permissions", "delete", $scope.fbRevokeCallBack);
} else { /*code here works fine*/ }
} else {
$scope.facebookLogin();
}
$scope.$apply();
});
}

Related

Payrexx integration in flutter webview

As described here https://developers.payrexx.com/docs/mobile-apps-javascript
I would like to interact with the javascript events of an iframe I want to create in the webview_flutter plugin.
The following example code is given in the official documentation
window.addEventListener('message', handleMessage(this), false);
and
function handleMessage(e) {
if (typeof e.data === 'string') {
try {
var data = JSON.parse(e.data);
} catch (e) {}
if (data && data.payrexx) {
jQuery.each(data.payrexx, function(name, value) {
switch (name) {
case 'transaction':
if (typeof value === 'object') {
if (value.status === 'confirmed') {
//handling success
} else {
//handling failure
}
}
break;
}
});
}
}
}
Do you know a way to do this? I have implemented an iframe in which there is the address of my gateway, but it is impossible to check if the payment has taken place.
Sounds good. The Payrexx iFrame sends a post message with the transaction details (including transaction status) to the parent window (e.g. your Flutter webview) after the payment (on the Payrexx result page). So you only need to add an event listener for type "message" in your webview as in the example:
window.addEventListener('message', handleMessage(this), false);
Please make sure you also send a post message into the Payrexx iFrame as soon as the iFrame is loaded (onload event):
let iFrame = document.getElementById('IFRAME-ID');
if (iFrame) {
iFrame.contentWindow.postMessage(
JSON.stringify({
origin: window.location.origin,
}),
iFrame.src,
);
}
Now you are ready to receive and handle the messages from the Payrexx iFrame:
private handleMessage(e): void {
try {
let message = JSON.parse(e.data);
if (typeof message !== 'object' ||
!message.payrexx ||
!message.payrexx.transaction) {
return;
}
let transaction = message.payrexx.transaction;
console.log(transaction);
} catch (e) {
}
};
Last but not least:
Make sure you also check the transaction status via transaction webhook (server-to-server notification):
https://docs.payrexx.com/developer/guides/webhook

FB Graph Api FB.getLoginStatus wrapper function returning undefined

I wrote a wrapper function for the FB.getLoginStatus that is defined as follows:
this.isLoggedInFB = function() {
FB.getLoginStatus(function(response) {
if(response.status == 'connected')
{
return true;
}
else if(response.status =='not_authorized'){
return true;
else{
return false;
}
});
}
Whenever I make the following alert
alert(myClass.isLoggedInFB());
I get undefined.
When I add an alert within the body of isLoggedInFB to see if FB is defined I get:
[Object object]
which tells me that it FB.init has been called, which is confusing because
that is the only thing that I thought could have gone wrong.
Finally, I made an alert to see if I mistyped the name or that my name-spacing was wrong by doing
alert(myClass.isLoggedInFB);
and I got the correct function definition.
because the function isLoggedInFB does not return any value. if you need to get the response data back you need to return a value like this:
var connected = 0;
this.isLoggedInFB = function() {
FB.getLoginStatus(function(response) {
if(response.status == 'connected')
{
connected = 1;
return true;
}
else if(response.status =='not_authorized'){
{
connected = 1;
return true;
}
else{
connected = 0;
return false;
}
});
return connected;
}

Permanent access token for the facebook app on a website

I need help to make a facebook app on my website permanent. The access token keeps expiring and i dont know how to get a permanent token.
Im using the fb.wall from "http://www.neosmart.de/social-media/facebook-wall/"
Here is my code:
<script type="text/javascript">
$(function () {
$('#example1').fbWall({
id: 'Facebookuser',
accessToken: 'accesstokengoeshere',
showGuestEntries: false,
showComments: true, max: 5,
timeConversion: 24
});
});
</script>
Instead of trying to get a permanent access token, try making a call to a function like this one each time where you have 'accesstokengoeshere':
function getAccessToken () {
FB.getAuthResponse(function(response) {
if (response.status == 'connected') {
return response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// if the user is not logged in to FB, prompt them to do so
// later might want to change this so it doesn't automatically prompt you to login
FB.login(function(response) {
return getAccessToken();
});
} else {
FB.login(function(response) {
return getAccessToken();
});
}
});
}

FB.api('/me/photos', function(result) {} doesn't return anything in Safari

$('#login').live('click',function(e){
$(this).hide();
login();
});
// login
function login(){
FB.login(function(response) {
if (response.authResponse != 'undefined' && response.authResponse != null) {
FB.getLoginStatus(function(response) {
// remember user ID
uID = response.authResponse.userID;
if(uID) getMostTagged();
});
} else { alert('User cancelled login or did not fully authorize.'); }
},{scope: 'user_photos,user_videos,user_photo_video_tags'});
}
// get friend with most pic tags
function getMostTagged(){
FB.api('/me/photos', {fields: 'tags'}, function(result) {
console.log(result);
}
The problem is that there is nothing in the result in Safari whereas its works fine in Firefox and Chrome...
Sorry I logged with wrong Facebook ID and thats why I couldn't get anything.

Facebook Session is not persisting from page - to - page

I am having a rough time with getting the facebook javascript SDK workflow to work. The requirement was to offer a "login" link, not a facebook icon. To do this, I improvised a bit. So far it works really well but the session is not persisting from page to page. I am figuring that the session gets set after the login method but it doesn't look like that. Here is login / logout which works fine:
function login() {
FB.login(function(response) {
if (response.session) {
FB.api('/me', function(response) {
document.getElementById('socialauth').innerHTML = "<span>Welcome, " + response.name + " </span>"
+ "(logout)";
});
} else {
}
}, { perms: 'email,publish_stream' });
return false;
}
function logout() {
FB.logout(function(response) {
document.getElementById('socialauth').innerHTML = "login";
});
}
And here is what I am testing with which doesn't fire:
$(document).ready(function() {
FB.getLoginStatus(function(response) {
if (response.status == "connected") {
// logged in and connected user, someone you know
alert("ok - 5 seconds has passed");
} else {
// no user session available, someone you dont know
alert("not ok");
}
});
});
I am also trying "javascript:document.cooike" in my URL box and see not evidence of the FB session.
Kindly advise?
You need to make sure your loading the Facebook SDK on each page as well. For a simple solution that uses jQuery check out https://github.com/xocialhost/jquery.xocialCore.js
The first two functions in the plugin deal with initializing FB and authentication.
Using the provided function you'd do something like this:
$(document).ready(function() {
$.xcInitFacebook = function({appId:'yourappid',callback:function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') { alert('logged in'); }
else { alert('not logged in'); }
} });
});