BASIC

Author Topic: Facebook connection  (Read 23566 times)

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Facebook connection
« on: 2011-Jul-14 »
1) Go to http://www.facebook.com/developers
2) Click "+ Create New App" in the top right
3) Name the App accordingly, tick the terms and click "Continue"
4) Fill in the captcha
5) Enter a relevant name in the Canvas Page (http://apps.facebook.com/yourname/)
6) Enter your canvas url (http://www.yourdomain.com/folderwithzipcontents/
7) Click "Save Changes"
8) Click "Web" on the left navigation
9) For site url use "http://yourdomain.com"
10) For site domain use "yourdomain.com"
11) Copy your App ID and App Secret
12) Click "Save Changes"

Now it's simply a matter of editing the config.php file with the appid and appsecret and then uploading the contents of the zip archive to the folder defined in step 6. Accessing http://www.yourdomain.com/folderwithzipcontents/update_status.php will now do it's stuff.

It's very basic but it does work. Hope you can dabble and expand upon it :)

** Note **
To get your access token for your created app visit  http://www.facebook.com/developers again and click on your app from the left-hand side. You will now see the full details of your app and a code will be displayed in the Access Token field. If there is no access token there click the given link to grant permissions, a code will now be shown. This access token is needed in the new updated code attached.




[attachment deleted by admin]
« Last Edit: 2011-Jul-15 by spicypixel »
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Omadan

  • Dr. Type
  • ****
  • Posts: 374
    • View Profile
    • Top Arcade Apps Games
Re: Facebook connection
« Reply #1 on: 2011-Jul-14 »
Thanks spicy, really helpful. After the so many things I tried yesterday this was one of them. And i get this error again with your info. "Facebook needs the CURL PHP extension". Is it that my webhost doesn't support cUrl?

Thanks for help spicy, your step by step was very well explained. Now about this error, no idea what to do.
Top Arcade Apps - Best game for mobiles and computers

http://www.toparcadeapps.com

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10709
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Facebook connection
« Reply #2 on: 2011-Jul-14 »
You must install the curl extension. I found this script to test the things you need.

Code: GLBasic [Select]
    $curlcontent="curl";
    $curlstatus="Curl is not installed  - This is a Problem";
    if (function_exists('curl_init')) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'https://api.facebook.com/restserver.php');
       curl_setopt($ch, CURLOPT_HEADER, 0);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
       $curlcontent = curl_exec($ch);
       curl_close($ch);
       $curlstatus="Curl is available but cannot access Facebook - This is a problem ";
       if (strlen($curlcontent)>6) {$curlstatus="Curl is available and can access Facebook - All is OK";}
    }
 

Would there be a safe way to host such a script on GLBasic.com for _all_ users, but prevent it from being abused? I'd host it then for you all.

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Facebook connection
« Reply #3 on: 2011-Jul-15 »
You could host the facebook.php script Gernot which would then be referenced in the config.php this should work. I've now amended the update_status.php script too.

Code: GLBasic [Select]
<?php
$msge = $_POST['mymsg'];
$msge = scrub($msge);

require_once 'fbconfig.php';

$attachment =  array(
         'access_token' => "mytokenhere",
          'message' => $msge,
                'name' => "BHPool Player Management System",
                'link' => "http://bhpool.spicypixel.net",
                'description' => 'Posted from the BHPool Facebook App',
          'picture'=>"http://bhpool.spicypixel.net/image.jpg",
        );
$facebook->api('/me/feed', 'POST', $attachment);

header('Location: http://bhpool.spicypixel.net');

// .----------------------------------------.
// | Prevent XSS Hacks & Mail Injection     |
// '----------------------------------------'
function scrub($EXPLOIT) {
         // Pre-Scrub with HTMLENTITIES
         $EXPLOIT = htmlentities($EXPLOIT,ENT_QUOTES);
         // Mail Check for exploit
         $scrubbed = preg_replace("(\n|\r)", "<br />", $scrubbed);
         // Return Value
         return $scrubbed;
}
?>
 

In the example above I'm using my own details (access token) for a website I made hence the header('Location: http://bhpool.spicypixel.net'); command which jumps back to my website when the status is updated. I've used _POST to grab the message from a form but I could easily have used _GET which is more appropriate from an app.

Examples:
www.yourdomain.com/update_status.php?mymsg=HelloWorld
www.yourdomain.com/update_status.php?name=spicy&score=2
« Last Edit: 2011-Jul-15 by spicypixel »
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10709
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Facebook connection
« Reply #4 on: 2011-Jul-15 »
ok. with the access token being an unique ID for the person/app that's posting, I can safely put this on my server?
Can you post your scrub function?
« Last Edit: 2011-Jul-15 by Kitty Hello »

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Facebook connection
« Reply #5 on: 2011-Jul-15 »
Thanks spicy, really helpful. After the so many things I tried yesterday this was one of them. And i get this error again with your info. "Facebook needs the CURL PHP extension". Is it that my webhost doesn't support cUrl?

Thanks for help spicy, your step by step was very well explained. Now about this error, no idea what to do.

It's your webhost not supporting cURL you may find that they only support v4 of php too not v5 not sure if that makes a difference but it might.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Facebook connection
« Reply #6 on: 2011-Jul-15 »
I've just made a GLB Status Updater App in facebook which you can test out here
« Last Edit: 2011-Jul-15 by spicypixel »
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Facebook connection
« Reply #7 on: 2011-Jul-15 »
ok. with the access token being an unique ID for the person/app that's posting, I can safely put this on my server?
Can you post your scrub function?

Yes you only need to host the facebook.php file though similar to how people link to the google version of jquery. This should then allow (in theory) the users to host the other files on their own webhost safely. They would change the config.php file to reference your facebook.php file on your server. This would be completely safe.

The scrub function is in the code above however the facebook_update.zip I removed the function and performed the commands directly as it seemed faster when submitting to facebook and prevented null text from being submitted.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Omadan

  • Dr. Type
  • ****
  • Posts: 374
    • View Profile
    • Top Arcade Apps Games
Re: Facebook connection
« Reply #8 on: 2011-Jul-15 »
Thanks spicy for everything. LOLLL i was doing correctly the first time I tried, it was just my stupid webhost not supporting cUrl.
I tried a free webhost with cUrl pre-installed and voila, I post no problems. Now comes the other part. From glBasic can this be only called from NETWEBEND, and if so this ends the program, not what I really want. Can we work this with Netwebget$, or is there a way around using NETWEBEND without ending the app.

Thanks a lot for your help. Ill start some testing with netwebget, but I dont think the php script will run the browser.
Top Arcade Apps - Best game for mobiles and computers

http://www.toparcadeapps.com

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Facebook connection
« Reply #9 on: 2011-Jul-15 »
Yeh i was thinking about doing the GLBasic side of things next, see what I can come up with ;)
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Omadan

  • Dr. Type
  • ****
  • Posts: 374
    • View Profile
    • Top Arcade Apps Games
Re: Facebook connection
« Reply #10 on: 2011-Jul-15 »
Go for it spicy. :)
I have been testing and with netwebend works perfectly but app exits. Now what Im after of course.

If only netwebend would have like control as in: App stays running but like static/paused, then when you do your FB thing, control goes back to your App.
Top Arcade Apps - Best game for mobiles and computers

http://www.toparcadeapps.com

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Facebook connection
« Reply #11 on: 2011-Jul-16 »
Go for it spicy. :)
I have been testing and with netwebend works perfectly but app exits. Now what Im after of course.

If only netwebend would have like control as in: App stays running but like static/paused, then when you do your FB thing, control goes back to your App.

Post your glb source bud so I can see what you're doing within glb. Not your app off course but the netwebend part
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10709
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Facebook connection
« Reply #12 on: 2011-Jul-16 »
netwebend on V10 won't end if you set ALLOWESCAPE FALSE. Or was it AUTOPAUSE TRUE - check both or the online maunal.

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Facebook connection
« Reply #13 on: 2011-Jul-16 »
netwebend on V10 won't end if you set ALLOWESCAPE FALSE. Or was it AUTOPAUSE TRUE - check both or the online maunal.

Excellent ;-)
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: Facebook connection
« Reply #14 on: 2011-Jul-16 »
This page:
www.facebook.com/dialog/oauth?client_id=APP_ID&redirect_uri=YOUR_URL&display=touch

is the one to go to for granting permissions  (see http://developers.facebook.com/docs/guides/mobile/#web), but unfortunately NETWEBEND isn't a, 'neat', way to do it...
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary