mgcrea / cordova-facebook-connect

Cordova ARC plugin for the Facebook SDK
94 stars 43 forks source link

Cordova Facebook Connect Plugin

by Olivier Louvignes

DESCRIPTION

SAMPLE PROJECT GENERATION

You can generate a sample XCode project by running samples/ios/create.sh from the root of the repository.

PLUGIN SETUP FOR IOS

Using this plugin requires Cordova iOS.

  1. Make sure your Xcode project has been updated for Cordova

  2. Rename the ios folder to FacebookConnect, drag and drop it from Finder to your Plugins folder in XCode, using "Create groups for any added folders"

  3. Add the .js files to your www folder on disk, and add reference(s) to the .js files using <script> tags in your html file(s)

    <script type="text/javascript" src="https://github.com/mgcrea/cordova-facebook-connect/raw/master/js/plugins/FacebookConnect.js"></script>

  4. Add new entry with key FacebookConnect and value FacebookConnect to Plugins in Cordova.plist/Cordova.plist

  5. In the Build Settings tab, search for Other Linker Flags. Add the value -lsqlite3.0.

  6. In the Build Phases tab, link binary with libraries section. Add the Social.framework, Accounts.framework and AdSupport.framework frameworks. Make them optional to support pre-iOS6 devices.

  7. Modify your application .plist according to the Facebook iOS : Getting started guide, check the Modify the app property list file section.

create an array key called URL types with a single array sub-item called URL Schemes. Give this a single item with your app ID prefixed with fb: ScreenShot. This is used to ensure the application will receive the callback URL of the web-based OAuth flow.

PLUGIN SETUP FOR ANDROID

Using this plugin requires Cordova Android.

  1. Make sure your Android project has been updated for Cordova

  2. Add the src/android folder from this plugin to your projet.

  3. Refresh (fn-F5), right-click on the facebook-android-sdk.jar & select Build path > Add to build path (the debug version will output to the console).

  4. Add the .js files to your assets/www folder on disk, and add reference(s) to the .js files using <script> tags in your html file(s)

    <script type="text/javascript" src="https://github.com/mgcrea/cordova-facebook-connect/raw/master/js/plugins/FacebookConnect.js"></script>

  5. Add new entry with key FacebookConnect and value org.apache.cordova.plugins.FacebookConnect to Plugins in res/xml/config.xml

JAVASCRIPT INTERFACE (IOS/ANDROID)

// After device ready, create a local alias
var facebookConnect = window.plugins.facebookConnect;

facebookConnect.login({permissions: ["email", "user_about_me"], appId: "YOUR_APP_ID"}, function(result) {
    console.log("FacebookConnect.login:" + JSON.stringify(result));

    // Check for cancellation/error
    if(result.cancelled || result.error) {
        console.log("FacebookConnect.login:failedWithError:" + result.message);
        return;
    }

    // Basic graph request example
    facebookConnect.requestWithGraphPath("/me/friends", {limit: 100}, function(result) {
        console.log("FacebookConnect.requestWithGraphPath:" + JSON.stringify(result));
    });

    // Feed dialog example
    var dialogOptions = {
        link: 'https://developers.facebook.com/docs/reference/dialogs/',
        picture: 'http://fbrell.com/f8.jpg',
        name: 'Facebook Dialogs',
        caption: 'Reference Documentation',
        description: 'Using Dialogs to interact with users.'
    };
    facebookConnect.dialog('feed', dialogOptions, function(response) {
        console.log("FacebookConnect.dialog:" + JSON.stringify(response));
    });

});

BUGS AND CONTRIBUTIONS

Patches welcome! Send a pull request. Since this is not a part of Cordova Core (which requires a CLA), this should be easier.

Post issues on Github

The latest code (my fork) will always be here

LICENSE

Copyright 2012 Olivier Louvignes. All rights reserved.

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

CREDITS

Contributors :

Inspired by :