How to use methods of Cordova Facebook Plugin? - android

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.

Related

Social Sharing in Cordova Application IOS

I am trying to share image particularly in WeChat and WhatsApp by using this plugin : EddyVerbruggen/SocialSharing-PhoneGap-Plugin
window.plugins.socialsharing.shareVia('whatsapp','msg',null,
'images/hello.png' , null /* url */, function(e) {
console.log('share' +e)
}, function(errormsg){
alert(errormsg)
})
window.plugins.socialsharing.shareVia('com.tencent.mm','msg',null,
'images/hello.png' , null /* url */, function(e) {
console.log('share' +e)
}, function(errormsg){
alert(errormsg)
})
My app gets crashed in ios but in android it works fine.
by using another method shareViaWhatsapp:
window.plugins.socialsharing.shareViaWhatsApp('Message via WhatsApp'
,'images/hello.png', function() {
console.log('share ok')
}, function(errormsg){
alert(errormsg)
})
This method working in android but in ios its showing all the apps to share when i share image, If i share only message its working properly in ios. Please guide me.
Sharing to whatsApp with shareViaWhatsApp is not working on iOs also in my case I can confirm.
Only way I was able to share picture was using share sheet with the plugin you mentioned.
So its something like:
this.socialSharing.share(null, null, this.screen, null).then(() => {
console.log(' succ share test')
this.shareWhatsApp()
}).catch((e) => {
console.log(' err share test')
this.shareWhatsApp()
});

Launching Ionic app using web URL

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 have ngOauth access_token now what?

So I am trying to add a login with facebook / twitter option to my mobile app. I have installed ngcordova oauth plugin and everything is working. User clicks login, it takes them to FB, they accept the permissions, takes them back to the app, and I have the access_token object. Perfect. Except what do I do with it now? Now that I have the token I should be able to request the specific info I need (email / name) How is this done? Do I have to install the ios & android facebook sdk and the ios & twitter sdk? Is this built into ionic? can I simply use web calls? I am very confused on how I actually get user email / whatever other info I requested in the access_token after I retrieve permission. Here is my code currently
$scope.facebookLogin = function() {
$cordovaOauth.facebook("xxxxxxxxxxxxx", ["email"]).then(function(result) {
// results
console.log("Success");
console.log(result);
}, function(error) {
// error
console.log("Failure");
console.log(error);
});
}
I am getting in the success block, but now I need to know what to do with the access_token to actually get values.
This is the solution that I found that actually works for future persons
$accessToken = result.access_token;
$http.get("https://graph.facebook.com/v2.4/me", { params: { access_token: $accessToken, format: "json" }}).then(function(result) {
//this is where the user data is stored
var user_data = result.data;
console.log(user_data);
}, function(error) {
console.log(error);
});

Cannot share custom text on facebook with cordova socialsharing plugin on android

I am building an app, using cordova, for android and iphone. I have this function to share some text on facebook:
window.plugins.socialsharing.canShareVia('com.facebook.katana', 'msg', null, null, null,
function () {
window.plugins.socialsharing.shareViaFacebook("Some custom text here" + link),
null,
null,
console.log('share ok'), // success callback
function (errormsg) {
alert(errormsg);
}); // error callback
},
function () {
console.log("NO FACEBOOK AVAILABLE");
navigator.notification.alert('The Facebook app is not available on your device.', // message
console.log('facebook app not installed'), // callback
'Share', // title
'Ok' // buttonName
);
});
In iphone is all working fine, i can share the text and the link on facebook thought the native app. In android, the facebook app will open but the custom text is missing, although the link do appear.
You can see the resulting post here: https://www.dropbox.com/s/bo0ughcv9w36zec/Screen_Shot.png
I have found some posts: https://developers.facebook.com/blog/post/510/ stating the custom message will be ignored, but I'm not sure this applies, besides in ios is working properly. Any help will be appreciated. Thank you.
It seems that Facebook does not allow, in their facebook app for android, to add custom text, we can only share a link. More info can be found here: https://developers.facebook.com/bugs/332619626816423

Phonegap facebook plugin for android gives me an oauthexception

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.

Categories

Resources