GithubHelp home page GithubHelp logo

matthewswallace / extension-facebook Goto Github PK

View Code? Open in Web Editor NEW

This project forked from haxeextension/extension-facebook-alt

0.0 2.0 0.0 41.9 MB

OpenFL extension to use Facebook in your app

License: MIT License

Haxe 72.73% Objective-C 5.72% Objective-C++ 21.25% Batchfile 0.31%

extension-facebook's Introduction

extension-Facebook

OpenFL extension to use Facebook in your app

/!\ Android only compatible with legacy build at the moment!

If you use ios-legacy backend (-Dlegacy), use the legacy branch.

Instalation

Clone this repo, then use the command below :

haxelib dev facebook path/to/clone

Install the msignal lib as well :

haxelib install msignal

then build the extension :

lime rebuild facebook ios

Use

Add a setenv tag in you project.xml to set your facebook application ID and application display name:

<setenv name="FACEBOOK_APP_ID" value="5898465436219" />
<setenv name="FACEBOOK_APP_DISPLAY_NAME" value="TestExtension" />

Then add the haxelib tag :

<haxelib name="facebook" /> 

Now you are ready to use the extension in your application.

Android Specific step

Key Hashes

Facebook asks for a key hashe when configuring your app for facebook. Your have to generate a keystore. Then use the bat in the sample folder to get your keyhase.

iOs Specific step

Add these lines in your PROJ-Info.plist template, before the final closing </dict>:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb::ENV_FACEBOOK_APP_ID::</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>::ENV_FACEBOOK_APP_ID::</string>
    <key>FacebookDisplayName</key>
    <string>::ENV_FACEBOOK_DISPLAY_NAME::</string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>facebook.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>fbcdn.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>akamaihd.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>

If you don't have an PROJ-Info.plist yet, you can find the default template here:

https://github.com/openfl/lime/blob/master/templates/iphone/PROJ/PROJ-Info.plist

To use it, save it at templates/iphone/PROJ/PROJ-Info.plist, and add this line in your project.xml:

<template path="templates" />

If you use other extennsions that templates that file, you'll have to merge it in yours.

You can as well use the command

haxelib run facebook project.xml

To apply the change to ther plist file, but you'll need to run it after every lime update or clean build.

Basic Sample

Facebook Login

// Wrote the samples in github edit mode, errors may appear...
import openfl.display.Sprite;
import openfl.events.MouseEvent;
import extension.facebook.LoginHelper;
import extension.facebook.AccessToken;

class FacebookLoginDemo extends Sprite {

  var mHelper : LoginHelper;
  var mUserId : String;

  function new(){
    super();
    
    mHelper = new LoginHelper(onLoggedIn, onLoggedOut, onLogginError, onLoginCancel);
    mHelper.init(); // this check if the user was loggedIn before, and trigger onLoggedIn if it was the case.
    
    var btnLogIn = new Sprite();
    btnLogIn.graphics.beginFill(0x0000ff);
    btnLogIn.graphics.drawRect(0,0,100,33);
    btnLogIn.addEventListener(MouseEvent.CLICK, onLoginCLicked);
    addChild(btnLogIn);
    
    var btnLogOut = new Sprite();
    btnLogOut.graphics.beginFill(0xff0000);
    btnLogOut.graphics.drawRect(0,0,100,33);
    btnLogOut.addEventListener(MouseEvent.CLICK, onLogOutClicked);
    addChild(btnLogOut);
    btnLogOut.y = 100;
  }
  
  function onLoginClicked(e : MouseEvent) {
    mHelper.logIn();
  }
  
  function onLogOutClicked(e : MouseEvent) {
    mHelper.logOut();
  }
  
  function onLoggedIn(){
    mUserId = AccessToken.getCurrent().getUserId();
    trace("Your user id is : " + mUserId);
  }
  
  function onLoggedOut() {
    trace("logged out");
  }
  
  function onLogginError(e : String) {
    trace("error : "  + e);
  }
  
  function onLoginCancel() {
    trace("You have to log in to use my awesome app.");
  }

}

A Graph Request

Use this tool to test graph request : https://developers.facebook.com/tools/explorer/

  import extension.facebook.Request;

  function getUserName() {
    var params = {
      fields : "id,name"
    }
    
    var request : Request = new Request("me", params);
    request.load(onRequestSuccess, onRequestFail);
  }
  
  function onRequestSuccess(data : Dynamic){
    trace("Your name is : " + data.name);
  }
  
  function onRequestFail(e : FacebookError){
    trace("Request fail : "  + e);
  }

Permissions

  import extension.facebook.Request;
  import extension.facebook.Permission;
  
  function askPermission(){
    // try to read user friend list. If we don't have the permission, we ask for it, then perform the request
    Permission.doWithRead([Permission.USER_FRIENDS ], onAccept, onRefused, onError);
    // use doWithWrite if you want some write permissions
  }
  
  function onAccept(){
    var request = new Request("me/friends");
    request.load(onSuccess, onRequestError);
  }
  
  function onSuccess(data : Dynamic){
    trace(data);
  }
  
  function onRequesterror(e : String){
    trace("error : " + e);
  }
  
  function onRefused(){
    trace("Please accept the permission so we can ask gift to your friends :'(");
  }
  
  function onError(){
    trace("Shit happens");
  }

extension-facebook's People

Contributors

tomobodo avatar paulgene avatar daphyre avatar

Watchers

Matthew Wallace avatar James Cloos 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.