I'm having such a big headache trying to use the Facebook plugin of Phonegap Cordova 2.3.0 on Android
I've installed the last Facebook Android SDK (3.0) and it works fine as I'm able to launch the examples and they work.
But I'm not so lucky with Phonegap because neither the examples are working, the problem is that when calling this:
FB.login(
function(response) {
//NEVER FIRED !!
alert(JSON.stringify(response));
if (response.session) {
alert('logged in');
} else {
alert('not logged in');
}
},
{ scope: "email" }
);
when I click on login button I call the FB.login and a dialog is shown asking permission to read user personal data. When I click "ok" the dialog disappear and nothing else happens.
I tried to debug the plugin (ConnectPlugin.java) and I see it correctly calls the method:
public PluginResult execute(String action, JSONArray args, final String callbackId)
and all parameters seem to have correct values. When the plugin makes the call I get this JSON:
{Session state:CLOSED_LOGIN_FAILED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:xxxxxxxx}
in the following method:
onSessionStateChange(SessionState state, Exception exception)
I can't understand where is the problem... whet is this code CLOSED_LOGIN_FAILED ?
Well, the solution is so trivial that I am ashamed... I didn't set up the Android section on the Facebook App configuration!
Related
Im using ngOpenFB on Ionic, and Ive got my callback set to localhost:8100/oauthcallback.html
$scope.submit= function () {
ngFB.login({scope: 'email'}).then(
function (response) {
if (response.status === 'connected') {
alert('Facebook login succeeded');
} else {
alert('Facebook login failed');
}
});
}
When I hit submit, the oauthcallback.html window gets opened, and in the url I see the valid access token. However, neither of the alerts fire. Theres is no success, and no failure. Just a blank oauthcallback.html page, with the access token in the URL.
I know I can use some trickery to just get that token from the URL and close the window myself. But surely this should be automatic in the ngOpenFB library?
Like it should do it for me no?? Store in sessionStorage, and close the window.
Otherwise, if I don't solve this, Im just going to do it the hacky way, and get the token, and save it myself.
But any ideas on why its not working as it should?
Here is my situation:
User request an email of forgot password.
User use their Android/iPhone to open email and tap on the link inside the email
When the link is tapped (clicked), it'll call the Ionic app.
I spend the whole morning to research and found this solution: using a plugin of Cordova named Custom-URL-scheme.
I also found out a tutorial from sysgears that I need to add this code into my app.js file:
.run(['$state', '$window',
function($state, $window) {
$window.addEventListener('LaunchUrl', function(event) {
// gets page name from url
var page =/.*:[/]{2}([^?]*)[?]?(.*)/.exec(event.detail.url)[1];
// redirects to page specified in url
$state.go('tab.'+ page, {});
});
}
]);
function handleOpenURL(url) {
setTimeout( function() {
var event = new CustomEvent('LaunchUrl', {detail: {'url': url}});
window.dispatchEvent(event);
}, 0);
}
I've done everything, however it does not work. I tried to type my URL_SCHEME (http://myapp://) into the Chrome browser in Android phone but Chrome just display an error message:
This webpage is not available. ERR_NAME_NOT_RESOLVED.
Please help me. Thanks.
Try to remove the "http://" from your sheme, href and browser
If still not working, can you precise your cordova version, and the plugin version you use. Did you install the plugin with the sheme in --variable URL_SCHEME=myapp
Also, note its "SHEME", not SHEMA
I am using Facebook plugin (http://ngcordova.com/docs/plugins/facebook/
) of Cordova. I am using this plugin with ionic framework. I am all done with installing this plugin on android. I have created an appId and the app is under development. So for the testing I am using test user generated in - https://developers.facebook.com/apps/123456789/roles/test-users/ I want to share a feed on Facebook but I am not able to do that. I am checking getLoginStatus method and on its success I want to post a feed. Here is my code
$scope.getFbLoginStatus = function(){
$cordovaFacebook.getLoginStatus()
.then(function(success) {
alert("Logged In");
$scope.shareFeed = function(){
$cordovaFacebook.showDialog({method: "feed", link:"https://github.com/Wizcorp/phonegap-facebook-plugin/commit/7b4a56f5717a50d3387abe4a2fa6156fe1aea852", caption: "Here is the caption"
})
.then(function(success) {
alert("check whether image shared or not" );
// success
}, function (error) {
alert("image not shared");
// error
});
}
}, function (error) {
alert("Permission denied");
});
}
I have not used facebook SDK as it was not listed in the installation steps.
I want to implement Facebook feed dialog using ionic framework. Please help me and suggest where I am going wrong.
There was problem in the Facebook app-id. It is working fine now. Make sure you generate the correct key hash for the settings of Facebook app_id.
I need help using Facebook SDK for Unity3d in android. I was trying to do all the tutorial said, but I can't login succesfully. I do FB.Init and its ok, but FB.Login never works. Always return this:
{
"is_logged_in":false,
"user_id":"",
"access_token:"",
"access_token_expires_at":"01/01/0001 00:00:00"
}
please, i need fix it as soon as possible.
Thanks for all.
i had the same problem this fixed it for me i was using the wrong keyhash in facebook, maybe you have the same problem
open the AndroidFacebook script and scroll till you see this:
public void OnLoginComplete(string message)
{
var parameters = (Dictionary<string, object>)MiniJSON.Json.Deserialize(message);
if (parameters.ContainsKey("user_id"))
{
isLoggedIn = true;
userId = (string)parameters["user_id"];
accessToken = (string)parameters["access_token"];
accessTokenExpiresAt = FromTimestamp(int.Parse((string)parameters["expiration_timestamp"]));
}
if (parameters.ContainsKey("key_hash"))
{
keyHash = (string)parameters["key_hash"];
print (keyHash);
}
OnAuthResponse(new FBResult(message));
}
as you can see inside where it pertains to keyhash i put
print (keyHash);
so now if you run it and log in and use logcat on eclipse or a logger to see the print() that come out of the code check the keyhash you have in your facebook app and the one that is printed out with print (keyHash); witch is the correct one, hope this helps :)
seriously going insane here....
I'm trying to get the phonegap facebook plugin for android to work, but it's really driving me up the wall (no pun intented).
I am using the code from https://github.com/irnc/phonegap-plugin-facebook-connect/tree/oauth-2.0+irnc, at least I think I am.
I appear to have two problems:
the following callback in the login (from pg-plugin-fb-connect) gives an error because "FB.Auth.setAuthResponse(response.authResponse, response.status);" cannot be found. Am I using an incorrect facebook sdk? Apparently no, see edit below
PhoneGap.exec(function (response) {
console.log('PG.FB.login.success: ' + JSON.stringify(response) + ', store into localStorage ...');
localStorage.setItem(key, JSON.stringify(response));
FB.Auth.setAuthResponse(response.authResponse, response.status);
if (cb) {
cb(response);
}
}, null, service, 'login', ['publish_stream', 'read_stream']);
},
When I comment the FB.Auth.setAuthResponse(response.authResponse, response.status); statement, my login returns successfull! I get an authresponse with an accesstoken and status set to connected. When I try to execute the following code (on success callback)
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
console.log(JSON.stringify(response.error, null, 4));
alert('We are very sorry, but somthing went wrong');
} else {
alert('Message was successfully posted to your wall!');
}
});
it gives me an oauthexception message: "An active access token must be used to query information about the current user."
I authenticated with 'read_stream, publish_stream' permissions.
These two are probably related, but I can't find anything about the setAuthReponse call in the facebook api.
EDIT help is apparently not on it's way, but i've continued my quest to get this to work.
The facebook js sdk I got from the github repo's are all using the 'old' auth methods. I've downloaded the new facebook js sdk and FB.Auth.setAuthResponse is there. I copied the code to my existing js sdk and changed all calls to setSession to setAuthRepsonse. Everything is working fine, except that the access token doesn't appear to be posted when I make above FB.api calls. After these changes, the error remains exactly the same!
Oh yeah, I also changed the check in the login callback to check for authResponse instead of session (it's in the example).
Help is more than welcome,
rinze
I think I fixed this. Basically the ConnectPlugin.java is still returning a "session" response object instead of the "authResponse" that the new SDK expects.
See https://github.com/odbol/phonegap-plugin-facebook-connect/commit/0ef84e29603338930ff82fc6d6ef8525b668077d for details.