Git Product home page Git Product logo

phonegap.facebook.inappbrowser's Introduction

phonegap.facebook.inappbrowser v 0.9 (not maintained anymore)

FacebookInAppBrowser uses the InAppBrowser Phonegap plugin and localStorage. Does not require any SDK from Facebook or other libraries.

This repo is based on this question and answer and on this repo using ChildBrowser

Until now "Login", "Logout", "Invite(Request)", "post(/feed)", "getInfo(/me)", "getPermissions(/id/permissions)" and "Share" are available.

Phonegap v2.8 up to 3.x

Setup

To use FacebookInAppBrowser you need to follow these steps:

  • Enable InAppBrowser in your Phonegap application as described in "InAppBrowser - Accessing the Feature". Instructions are the same for 2.8 up to 3.x except for the command line interface. If you have 3.x you need to install the InAppBrowser plugin trough the command line.
  • Enable Storage in your Phonegap application as described in "Storage - Accessing the Feature". If you have 3.x Storage is enabled by default.
  • Download the 'phonegap.facebook.inappbrowser.js' file and place it inside your project (for example in www/js/)
  • In your index.html place a script tag calling the javascript file:
<script type="text/javascript" src="js/phonegap.facebook.inappbrowser.js"></script>
  • You should have your main javascript file (also called in a script tag in your index.html). In it just configure and call FacebookInAppBrowser as the example below.

Basic example

// Settings
FacebookInAppBrowser.settings.appId = '123456789';
FacebookInAppBrowser.settings.redirectUrl = 'http://example.com';
FacebookInAppBrowser.settings.permissions = 'email';

// Optional
FacebookInAppBrowser.settings.timeoutDuration = 7500;

// Login(accessToken will be stored trough localStorage in 'accessToken');
FacebookInAppBrowser.login({
	send: function() {
		console.log('login opened');
	},
	success: function(access_token) {
		console.log('done, access token: ' + access_token);
	},
	denied: function() {
		console.log('user denied');
	},
	timeout: function(){
	    console.log('a timeout has occurred, probably a bad internet connection');
	},
	complete: function(access_token) {
		console.log('window closed');
		if(access_token) {
			console.log(access_token);
		} else {
			console.log('no access token');
		}
	},
	userInfo: function(userInfo) {
		if(userInfo) {
			console.log(JSON.stringify(userInfo));
		} else {
			console.log('no user info');
		}
	}
});

// Invite friends
FacebookInAppBrowser.invite('Get to know my app!', function(response) {
	if(response) {
		alert('success');
	}
});

// Same logic of callbacks
FacebookInAppBrowser.getInfo(function(response) {
	if(response) {
		var name = response.name,
            id = response.id,
            gender = response.gender;
	            
        // check the response object to see all available data like email, first name, last name, etc
        console.log(JSON.stringify(response));
	}
});

FacebookInAppBrowser.getPermissions(function(permissions) {
	if(permissions) {
		console.log(permissions.publish_actions, permissions);
	}
});

FacebookInAppBrowser.post({
	name: 'My post',
	link: 'http://frop.me',
	message: 'Try this out',
	picture: 'http://caiovaccaro.com.br/wp-content/uploads/2013/10/frop01.jpg',
	description: 'Sent trough mobile app'}, function(response) {
		if(response) {
			console.log('post successful');
		}
	});
	
// Share urls
FacebookInAppBrowser.share({
    href: 'https://developers.facebook.com/docs/'
}, function(response) {
    if (response) {
        alert('success');
    }
});

// Share open graph actions
FacebookInAppBrowser.share({
    action_type: 'og.likes',
    action_properties: JSON.stringify({
        object:'https://developers.facebook.com/docs/',
    })
}, function(response) {
    if (response) {
	    alert('success');
    }
});
// please note that you could get errors like:
// "User is already associated to the object type, article, on a unique action..."
// if you try to re-like something already liked by the user

// Logout
FacebookInAppBrowser.logout(function() {
	alert('bye');
});

If you are using jQuery or similar you can use it like:

// callbacks as before
$('#login').click(function() {
	FacebookInAppBrowser.login(...);
});

$('#invite').click(function() {
	FacebookInAppBrowser.invite(...);
}):

$('#bye').click(function() {
	FacebookInAppBrowser.logout(...);
});

Thanks

Thanks to:

  • @ilyakar
  • @jcoltrane
  • @complex857

phonegap.facebook.inappbrowser's People

Contributors

caiovaccaro avatar mandeeppasbola avatar jcoltrane avatar

Watchers

James Cloos avatar Rufo N. Gabrillo Jr. avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.