Cordova/Ionic Facebook getLoginStatus not working - ios

I am developing an App in Ionic/Cordova with Login over Facebook. Before showing the "Login-Page" I would like to check if the user is already connected.
The following getLoginStatus check works as expected in the iOS Simulator. When testing on the actual device, the getLoginStatus callback does not get fired.
facebookConnectPlugin.getLoginStatus(
function (response) {
if (response.status == "connected") {
set_tokens(response);
$location.path('/tab/person/me/events');
}
},
function (response) { alert(JSON.stringify(response)) }
);
Already set the Facebook-App to public and verified the App-Id.
Can anybody give a reason for the described behaviour?

I have the following implementation for Facebook login using facebookConnect Plugin.
facebookConnectPlugin.getLoginStatus(
function(response){
if(response.status == "connected"){
//do something, for example share or redirect
}else{
facebookConnectPlugin.login(["basic_info"],
function(success) { /*do something...*/},
function(error) {
//handle error
});
}
}, function(error) {
// handle error
})
}
If you still have errors, try to log the error and success events to see what is happening. This implementations works in a controller.

Related

How to debug an issue with Zendesk App as console.log is not working

topBarClient.request(settings).then(
function (data) {
console.log("data",data);
showTaskData(data);
if (data.status === 200) {
onSuccess(JSON.parse(data.responseText));
} else {
onFailure(data.status);
}
},
function (response) {
console.log("error", response);
onFailure(response.status);
}
);
onFailure is working but not able to get the error out
Is there a way to test this locally?
console.log works fine, if it's not working then it is not getting called probably due to some exception in the line above console.log.
If you face any problem you can render html component like div to dislplay the text for debugging purpose.

react-native error RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL)

I am trying to use react-native-fbsdk in my react-native app. It was working fine untill yesterday. But, today it gives a weird error stating RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL).
RN v0.42.0
Here is my code:
_fbAuth(error, result) {
if (error) {
console.log("error");
alert("login has error: " + result.error);
} else if (result.isCancelled) {
console.log("login cancelled");
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then((data) => {
console.log("login success");
console.log(data.accessToken.toString());
let accessToken = data.accessToken;
alert(data.accessToken.toString());
const responseInfoCallback = (error, result) => {
if (error) {
console.log(error);
} else {
console.log(result);
}
}
const infoRequest = new GraphRequest(
'/me',
{
accessToken: accessToken,
parameters: {
fields: {
string: 'email,name,first_name,middle_name,last_name'
}
}
},
responseInfoCallback
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start();
});
}
}
render() {
console.log("in new render");
return (
<View style={styles.container}>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={this._fbAuth}
onLogoutFinished={() => alert("logout.")}/>
</View>
);
}
The error information printed in debugger:
I get the above error while calling the graphAPI in the function responseInfoCallback. Any ideas what is happening ?
Update 1:
This error happens only when remote debugger is turned on!! Else it is not happening. But without remote debugger, I cannot proceed with developing the app. Are there any other methods to see log statements of react-native app other than remote debugger ?
Update 2:
The RCTJSONStringify() error happens only behind proxy. And also https fetch calls does not work under proxy. I tested in an open network, it works fine. I guess, it is to add some proxy information to RN app. I think it is related to APP transport security
If you turn the debugger off, you can see the proper error in the XCode console. Access it from Xcode menu View/Debug Area/Activate console, if it's not enabled automatically.

Image uploaded to Facebook but not shown on page

I am trying to upload an image to a specific album on Facebook page through Graph api call from ipad app. Everything is working correctly and the response from Facebook returns success with the id of post but I just can't see the image uploaded on the page. I am doing this using Appcelerator Titanium. Following is my code:
var fb = require('facebook');
fb.appid = 'MY APP ID';
fb.permissions = ['read_stream'];
function postImageToFb(){
fb.reauthorize(['publish_actions','manage_pages'], 'me', function(e){
if (e.success) {
// If successful, proceed with a publish call
var data = {
source: Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory+'/image.png').read(),
message: 'Hello pic'
}
fb.requestWithGraphPath('<album-id>/photos',data,'POST',function(e){
alert('Post to fb: '+JSON.stringify(e));
if(e.success){
alert('Photo submitted successfully to fb.')
}else{
alert('Failed to upload photo to fb: ')
}
})
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unknown result");
}
}
});
}
$.btn_submit.addEventListener('click',function(e){
if(fb.loggedIn){
postImageToFb();
}else{
fb.authorize();
fb.addEventListener('login',function(e){
if(e.success){
postImageToFb();
}else{
alert('Failed to login fb: ',e);
}
})
}
})
I have used the same account for creating Facebook app, page and Facebook login from app so it shouldn't be the problem. What might be the problem? Can someone help me. Thanks.
I could never get the requestWithGraphPath() to work with a page, even with the access token FOR the page. It would always post to the Pages wall, but as my personal profile.
See how I ended up doing it here (underneath the profile explanation is an explanation on Pages): https://stackoverflow.com/a/28144909/4121164

Adobe PhoneGap Build (iOS) and PushWoosh

According to the docs at PushWhoosh:
http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/
I should be able to use Adobe's Build cloud service to build PhoneGap apps. I've followed the instructions in the docs, but can't get my app to register with the PushWhoosh service (i.e.: it's not sending a device token).
I think the issue has to do with the registration of the plugin in config.xml. According to the Adobe Build docs, the only push plugin supported is their "GenericPush", which I've added to my config.xml file like so:
I've also whitelisted the pushwhoosh.com domain.
In my index.html file, I have the function initPushwhoosh, which gets called when the device is ready:
function initPushwoosh() {
try {
var pushNotification;
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(successHandler, errorHandler, { "senderID": "replace_with_sender_id", "ecb": "onNotificationGCM" });
}
else {
pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" });
}
}
catch (err) {
alert(err.message + "\n\n" + err.name);
}
}
And my tokenHandler function (I'm building for iOS) looks like:
function tokenHandler(result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
PushWoosh.appCode = "E0313-D27FA";
PushWoosh.register(result, function (data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function (errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
Through debugging, it looks like the "pushNotification.register" function never gets called, and the try/catch statement doesn't display any error messages. That function is:
// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android)
PushNotification.prototype.register = function (successCallback, errorCallback, options) {
alert("about to register");
if (errorCallback == null) { errorCallback = function () { } }
if (typeof errorCallback != "function") {
alert("PushNotification.register failure: failure parameter not a function");
return;
}
if (typeof successCallback != "function") {
alert("PushNotification.register failure: success callback parameter must be a function");
return;
}
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
};
My thinking is that it has to do with the plugin declaration (<gap:plugin name="GenericPush" />) in config.xml; I've tried changing it to (based on some other sample code I found):
<gap:plugin name="PushPlugin"/>
But that didn't work either. Note: when I did this, I tried changing:
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
to
cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]);
The complete code can be found here:
https://github.com/appburnr/PushWhooshTest
I've tripled-checked the my PushWhoosh AppID is correct, but I can never get the app to appear as registered device in my PushWhoosh control panel.
Any ideas?
Are you sure this code is correct?
pushNotification.register(successHandler, errorHandler, { "senderID": "replace_with_sender_id", "ecb": "onNotificationGCM" });
Shouldn't it be the Project ID from GCM? It might explain why the device doesn't register for push notifications.
I'm not familiar with PushWoosh, but they do have a guide to how to achieve this with Build here:
http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/
Have you followed each step?
If you still haven't had success (I hope you have) try this guide:
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
I've built a solution using push notifications myself now, and found my biggest issue was that I hadn't set up the certificates. This guide is perfect.
ALSO remember that push notifications won't work in the emulator, only on a real device.

Error in FB.login() phonegap facebook plugin

When i run fb.login() in an ios 6 device using the account setted in Settings/facebook i get the following
operation couldn't be completed (com.facebook.sdk error 2)
in ios 5 the app works perfectly, the problem is the native login
help please ! this is my code
this is the facebook init
this.appId = appId;
var me = this;
document.addEventListener('deviceready', function() {
try {
FB.init({ appId: "294003447379425", status: true, cookie: true, nativeInterface: CDV.FB, useCachedDialogs: false });
} catch (e) {
console.log(e);
}
}, false);
if (!this.appId) {
Ext.Logger.error('No Facebook Application ID set.');
return;
}
var me = this;
me.hasCheckedStatus = false;
FB.Event.subscribe('auth.logout', function() {
// This event can be fired as soon as the page loads which may cause undesired behaviour, so we wait
// until after we've specifically checked the login status.
if (me.hasCheckedStatus) {
me.fireEvent('logout');
}
});
// Get the user login status from Facebook.
FB.getLoginStatus(function(response) {
me.fireEvent('loginStatus');
clearTimeout(me.fbLoginTimeout);
me.hasCheckedStatus = true;
if (response.status == 'connected') {
me.fireEvent('connected');
Ext.Viewport.add(Ext.create('CinePass.view.Main'));
} else {
me.fireEvent('unauthorized');
console.log('noconectado');
Ext.Viewport.add(Ext.create('CinePass.view.LoggedOut'));
}
});
// We set a timeout in case there is no response from the Facebook `init` method. This often happens if the
// Facebook application is incorrectly configured (for example if the browser URL does not match the one
// configured on the Facebook app.)
me.fbLoginTimeout = setTimeout(function() {
me.fireEvent('loginStatus');
me.fireEvent('exception', {
type: 'timeout',
msg: 'The request to Facebook timed out.'
});
Ext.Msg.alert('CinePass', 'Existe un problema con Facebook, se iniciará la aplicación sin conexión a Facebook.', Ext.emptyFn);
Ext.Viewport.add(Ext.create('CinePass.view.Main'));
}, me.fbTimeout);
this is the login
FB.login(
function(response) {
if (response.session) {
alert(response.session);
} else {
alert(response.session);
}
},
{ scope: "email,user_about_me,user_activities,user_birthday,user_hometown,user_interests,user_likes,user_location,friends_interests" }
);
Having the same problem and took me few days to figure this out, there are a number of reasons:
1) The first time you launch your app, if you deny the "Do you allow this app to use your facebook permission", you'll get this error, what you need to do is, go to Setting > General > Facebook > turn on your app OR go to Setting > General > Reset > Reset Location & Privacy (this will reset and ask you the "Do you allow this app to use your facebook permission" again for all app.
2) Slow/No Internet can caused the error
3) Create your certificate again, and go to build.phonegap.com, create a new key for IOS and change the IOS key (This works for me, I have no idea how it works but it does, I notice a significant app file size increase after i use a new IOS Key)
4) If your app is in sand box mode, and your IOS current Facebook account is not an app tester you'll get the error too. I just disable the sand box mode and it works, make sure your Facebook App Setting has the correct bundle ID, if your app is still under developement, put 0 to app store ID.

Resources