Facebook application

ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Tue, 2007-05-29 20:50

Hi...

I'm not sure if this is the right forum for this but...

Has anyone looked into creating a facebook application now that facebook has opened up its API for developers? I was thinking that it'd be great to have an app that would selectively import albums from my Gallery install into my facebook profile.

I have a ton of images in my Gallery and never bother to import them to facebook as it's too much extra work. However, many of my friends don't see them as they don't venture out of facebook to look at the pictures (that's the point of social networking sites, right?) so the images aren't viewed by just having them in my Gallery. There is already a facebook app for iPhoto that does exactly this.

Does something like this sound interesting to others? Any thoughts or ideas?

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Tue, 2007-05-29 21:16

I was actually just going to make the same suggestion and you beat me by 20 minutes. It would be an AMAZING add-on to facebook because I, too, have a ton of photos that I would never bother importing to facebook because it would take way too long.

Sadly, I have no idea how to go about writing such code, but the developer tools are here:

http://developers.facebook.com/

 
hollyonline

Joined: 2006-09-13
Posts: 59
Posted: Thu, 2007-05-31 14:22

Superb idea - I was just talking to a friend recently and we thougth it would be great to integrate Gallery into Facebook. The only thing, is I've no idea how to go about it!

---
Robert Hollingworth
www.roberthollingworth.co.uk
www.theballphotographers.com

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Thu, 2007-05-31 14:36

I think I might try my hand at it - I have no idea what I'm doing so don't expect magic but if anyone wants to give advice or comments I would certainly welcome them.

I think it would be easiest to create a module for Gallery that would export to facebook...thoughts?

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Thu, 2007-05-31 22:35

I really have no idea if it's possible, but what about somehow linking an existing gallery to a facebook, whereby a facebook user could select albums to appear in facebook. The linked albums would look and operate just like ordinary facebook albums.

This could be really useful if picture tagging is ever implemented in gallery.

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Fri, 2007-06-01 17:16

Also -- this could ensure that updates to an album would be picked up by facebook without making all the changes yourself.

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Fri, 2007-06-08 04:08

Any developers want to volunteer to help out with this? I think I'm in over my head. :-)

 
sunnychan

Joined: 2007-06-08
Posts: 5
Posted: Fri, 2007-06-08 10:56

Yup I may give it a shot over the weekend. I don't promise anything though :-)

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Fri, 2007-06-08 12:13

Awesome! Let me know how it goes.

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Fri, 2007-06-08 15:21

I looked at the developer stuff and it seems like it would be really easy to get something basic out the door pretty fast. The fact that it's mainly PHP-based would make it super easy.

Something basic would create a section (or "window"?) on our facebook profile that would show a listing of all the albums in a Gallery "root." The listing would display the highlight picture for each album and simply link to the albums on our external sites.

Later on we could look at adding deeper integration, but this would be a great starting point.

I would love to try and do it myself, but I'm in the process of moving, and I'm going out of the country for a month next Saturday.

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Fri, 2007-06-08 15:58

I don't know if this is better or worse but the way I was thinking of implementing it was a module that plugged into gallery allowing the user to choose from a list of albums (or items) from a control panel page that he wanted to transfer to facebook. The album would then be created on facebook and then each of the child images in the album would be uploaded to fill the facebook album.

This approach would allow it to tie directly into facebook with all of the familiar notifications and news feed items (UserX has added a new gallery, etc). To a facebook user it would appear as if the gallery had been uploaded normally. A Gallery user could have his galleries in two places with just one upload action on the user's part. If you changed the Gallery album later these changes wouldn't be propagated across to facebook, however (or vice versa).

Alternatively, instead of a module page you could have a link on each album in the album actions that would allow the user to select that gallery for transfer to facebook and just store the users facebook credentials from the module setup page.

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Fri, 2007-06-08 20:38

Shorty --

All of the data (images and databases) need to be stored externally from facebook, so doing an import would really just be making another copy on our own servers to get them on facebook. Ergo, why not just have them linked from where they are?

In the long term, I definitely agree that any application should act and feel like the normal facebook photo albums, but I'd just like to get my pictures on my profile and then worry about that deeper integration later.

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Sat, 2007-06-09 00:55

I DID IT!!!

Granted, this is totally an alpha version, I got my albums listed on my facebook profile:

[img]http://www.newstohughes.com/images/gallery_for_facebook.jpg[/img]

The plugin is useless to anybody besides me because it doesn't allow you to pop in the information for your server, etc. But -- making the little script that I've written more customizable would be an awesome first step to getting the ball rolling here. Start with just listing the "root" albums automatically, then move into customizing which albums will be shown, and finally make it look and work just like facebook's photos albums.

Like I said, I'm moving and going on vacation for a month, so I won't be able to do anything else here, but if someone else wants to take this little script I started and run with it, please do. Details below...

Best,
Ryan

----------------

I followed the step-by-step instructions here:

http://developers.facebook.com/step_by_step.php

When I was done, I came out with these files:

index.php:

<?php
require_once 'dbappinclude.php';
require_once 'appinclude.php';

$html = "<table border=0>";
$count = 3;

$query = "select g_id from g2_ChildEntity where g_parentId=7";
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)){

if($count == 3) {$html .= "<tr><td width=122>";}
elseif($count == 0) {$count = 3; $html .= "<tr><td width=122>";}
else {$html .= "<td width=122>";}

$id = $row-> g_id;
$curl_handle=curl_init();
$url = "http://www.mysite.com/gallery/main.php?g2_view=imageblock.External&g2_blocks=specificItem&g2_itemId=$id&g2_show=title";

curl_setopt($curl_handle,CURLOPT_URL,$url);
 curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
 curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
 $buffer = curl_exec($curl_handle);
 curl_close($curl_handle);
 // print "$buffer";

$html = $html . $buffer;

if($count == 1) {$html .= "</td></tr>";}
else {$html .= "</td>";}

$count--;
}

if($count == 2) {$html .= "<td></td><td></td></tr>";}
elseif($count == 1) {$html .= "<td></td></tr>";}
 
$html .= "</table>";
 
print "$html";

$facebook->api_client->profile_setFBML($html, $user);
?>

appinclude.php:

<?php
require_once 'facebook.php';

$appapikey = '[my key]';
$appsecret = '[my secret]';
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login();

//[todo: change the following url to your callback url]
$appcallbackurl = 'http://www.mysite.com/gallery_for_facebook';

//catch the exception that gets thrown if the cookie has an invalid session_key in it
try {
  if (!$facebook->api_client->users_isAppAdded()) {
    $facebook->redirect($facebook->get_add_url());
  }
} catch (Exception $ex) {
  //this will clear cookies for your application and redirect them to a login prompt
  $facebook->set_user(null, null);
  $facebook->redirect($appcallbackurl);
}

dbappinclude.php:

<?php
require_once 'appinclude.php';

$dbhost = '[host]';
$dbuser = '[user]';
$dbpass = '[pass]';
$dbname = '[dbase]';

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $conn);

function query($q) {
  global $conn;
  $result = mysql_query($q, $conn);
  if (!$result) {
    die("Invalid query -- $q -- " . mysql_error());
  }
  return $result;
}
 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Sat, 2007-06-09 14:58

That's a good start! I guess I wasn't thinking of actually creating a facebook "application" that would actually connect to the database and pops into the profile page but rather just using the Facebook API to actually upload photos to facebook from Gallery. http://developers.facebook.com/documentation.php?v=1.0&doc=photoupload

I'm interested to know what others think.

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Sat, 2007-06-09 15:42

I didn't realize that functionality was available. Maybe a final version could include the capability to embed photos directly from Gallery the way I did and to import the way you are describing.

For me, displaying my photos directly from Gallery is a much more appealing option. That way, I don't have to upload them to Gallery and then do a Facebook import. Likewise, I wouldn't want to delete from Gallery and then from Facebook. Changes would show up automatically. Plus, Facebook lowers the quality of images significantly. I would much rather my high-quality images be shown.

But on the flip side, I can see why you would want to do the import with all of Facebook's tagging capabilities, etc.

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Sun, 2007-06-10 01:10

Exactly. Neither way is perfect and both have their uses. For me, I may only be able to do it with a direct upload because I believe my MySQL host (1&1) requires that the database be queried from within their firewall, i.e. no external queries.

 
rhughes2270

Joined: 2007-05-29
Posts: 9
Posted: Sun, 2007-06-10 13:45

Facebook applications reside on external servers. Facebook calls my PHP from their servers, and it runs on mine, executing all SQL queries locally. The results are piped through the locally run PHP script back to Facebook.

 
Nish Vamadevan

Joined: 2007-06-11
Posts: 1
Posted: Mon, 2007-06-11 22:49

Well, I think, It would be good if the Photos can be displayed randomly...

Currently, I am trying to make the make the API to list photos on an Album... But when you click the Thumb Nail, It will take the user to the Gallery URL... I think its hard / nearly Impossible to create an API to behave EXACTLY like the Facebook Album.

If I managed to do it, I will let you know.

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Tue, 2007-06-12 01:37

I created a simple FB Application that takes a Gallery URL, makes you pick one of the albums found at that URL, makes you choose which pictures from that album you want to upload, and then uploads all those photos into a new FB album that has the same name as the Gallery album.
If an album with the same name already exists, photos will be uploaded in it. It won't re-upload photos that it already uploaded before in this album.

You can try it here: http://www.facebook.com/apps/application.php?id=2390304162

Once added, you'll get a small block in your FB Profile page with a link:
"Gallery Import: You can start importing Gallery albums [here]."

There's probably a lot of quirks in it; it uses data-scrapping, so it might not work right with Gallery installations not using mod_rewrite, etc.

Feedback is welcome.

- Guillaume Boudreau

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Tue, 2007-06-12 03:48

This is exactly what I was looking for. Unfortunately, I can't get it to work. I put in the URL of the gallery (I've tried top level,, gallery with subalbums, and the lowest level URL) but it's unable to pull up a list of albums. I do use URL rewrite to format the URL to domain.com/gallery/CategoryAlbum/FinalAlbum/IMG_9999.JPG.html. Any ideas?

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Tue, 2007-06-12 11:53

I'd have to see the HTML source of your Gallery homepage to see what is different from mine.
I guess I data-scraped a part of the page that is only part of the theme I use...

(The URL you enter *must* be the homepage of your Gallery installation: http://domain.com/gallery for example).

Now that I think about it, we need a better way to get Gallery data than data-scraping. Anyone know an easy way to get a list of albums, or items in an album, in any text-only format (XML or text or JSON or ...)
For now, I think I'll just create a small PHP page that will query my Gallery database directly.

- Guillaume

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Wed, 2007-06-13 05:43

Also, possibly a "select all" "select none" button on the thumbnails page would be great. Ok, done for real.

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Tue, 2007-06-12 22:53

There. I added a helper script to install in your Gallery host that helps provide albums and photos information. I uses Gallery internal functions, so I didn't code any MySQL access or whatnot; nothing to configure in the helper script either.

Follow instructions found in the Step 1 (click the export_fb.php link) to install this helper script.

Still to fix:
When importing many pictures, the import step will often give an error. If this happens, first approve all the photos that the application was able to upload in FB, then hit Refresh in the Gallery Import application. The next photos will be uploaded.

Enjoy.

- Guillaume

 
sunnychan

Joined: 2007-06-08
Posts: 5
Posted: Tue, 2007-06-12 23:37

How about using the Gallery Remote interfaces?

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Tue, 2007-06-12 23:48

Can the Gallery Remote interfaces give information about photos items contained in Albums?
I never saw any photo information in Gallery Remote, only albums.

- Guillaume

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Wed, 2007-06-13 04:33

Ok, I made it a bit farther this time. I got the script uploaded to my server. In facebook I got the list of albums, selected one, viewed the list of images, and clicked continue. The album was created but no photos were imported. I tried this on several albums with the same results.

Thanks for your work on this, Guillaume, this will be great once the bugs are worked out.

-Ryan

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Wed, 2007-06-13 05:11

After taking a look at the output from the php script I see that it was looking for the "download" rewrite. I didn't have it activated but after doing so it was able to find the images and import them. I had some difficulty with the script apparently timing out. After refreshing the page a couple times most of them did import successfully. I say "most" because it cut my album off at 60 images. Would it be possible to automatically create a second album with the same name + "2" after it to upload the rest (or 3 or 4, etc). :-)

This is great. Thanks again.

-Ryan

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Wed, 2007-06-13 05:23

I'm noticing that it requires me to refresh the page while importing for every 20 images. If it's less than 20 no refresh is needed. (Last post of the night, I promise)

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Thu, 2007-06-14 17:53
ShortyR19 wrote:
I say "most" because it cut my album off at 60 images. Would it be possible to automatically create a second album with the same name + "2" after it to upload the rest (or 3 or 4, etc).

Done. New albums are created as needed now.

ShortyR19 wrote:
I'm noticing that it requires me to refresh the page while importing for every 20 images. If it's less than 20 no refresh is needed.

I asked about this in the FB discussion forum, and I'll update the app once I get a viable solution.
Until then, I'll show a 'click [here] to continue importing' every 15 photos, so it won't show errors.

ShortyR19 wrote:
Also, possibly a "select all" "select none" button on the thumbnails page would be great.

FB doesn't allow onclick JS on links, so I have to reload the whole page to select or deselect all photos. Not that cool, but it works.

I also changed the export_fb.php script to not use rewrite URLs anymore, so if you update it, you won't need the rewrite module anymore.

- Guillaume Boudreau

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Thu, 2007-06-14 20:37

I just imported an album with 150 images. Besides having to click continue (which is, though, a much better option than hitting refresh after seeing a "cannot connect" page) the process was great. The successive albums were created nicely and I didn't see any error messages.

Cool.

 
sebflipper

Joined: 2004-08-08
Posts: 18
Posted: Fri, 2007-06-15 12:53

Does this Facebook app export the images with the watermark? Because I have noticed that some Gallery modules seem to ignore images with watermarks and just use the original image instead.

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Fri, 2007-06-15 13:21

It exports the image that is shown at this URL:
http://your_gallery_url/main.php?g2_view=core.DownloadItem&g2_itemId=$photo->id&g2_serialNumber=1
where $photo->id is the ID of the photo item.

The watermark module seems to allow you to add watermarks to image when they are linked to on external websites.
This FB app doesn't link to images: it uploads them on FB.
If you can give me a generic URL to download a watermarked image, I could add an option in export_fb.php to use that URL or not.

- Guillaume Boudreau

 
sebflipper

Joined: 2004-08-08
Posts: 18
Posted: Sun, 2007-06-17 17:00

please delete/ignore

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Fri, 2007-06-15 17:59

Adding the application adds a block in the right column in your profile page.

- Guillaume Boudreau

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Fri, 2007-06-15 19:12

About watermarked images:
I changed the export_fb.php script to use the watermarked image, if there is one.
Just update it on your server and you should get watermarked images when importing into FB.

- Guillaume Boudreau

 
sebflipper

Joined: 2004-08-08
Posts: 18
Posted: Fri, 2007-06-15 22:00
gboudreau wrote:
About watermarked images:
I changed the export_fb.php script to use the watermarked image, if there is one.
Just update it on your server and you should get watermarked images when importing into FB.

- Guillaume Boudreau

Cheers for getting back so quickly, works like a treat! Thanks

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Sun, 2007-06-17 04:43

I modified the application to import all photos without user intervention; no need to click Continue each 15 photos now.

- Guillaume Boudreau

 
ShortyR19

Joined: 2007-05-29
Posts: 16
Posted: Sun, 2007-06-17 22:46

Awesome, Gillaume, it worked like a charm!

 
myobie

Joined: 2006-05-30
Posts: 18
Posted: Mon, 2007-06-18 12:23

Problem:

When importing, if I "select none" or "select all"
Im getting a 404 file not found error..

Also, all the pictures arent showing up.
eg: select album w 9 photos.

Page for photo selection shows just 1 photo (but says it found 9)

What permissions does this use for the import? (guest i hope!)

NB:
im not sure how this app is categorized in FB, but its not showing up under photos, or searching for gallery in the FB applications list.

Cheers
Craig

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Mon, 2007-06-18 13:47

Select All/None: Fixed; only the top Select All/None was working. Now both are.

By trying to export your 1st album with 9 photos (id=23), I saw that only one photo had a title; that caused your problem. Since the caption field is optional in FB, I'll just change the application code to allow empty titles. It should work better now.

Also: I saw in the albums export of your Gallery that some albums have a line feed in their titles, which breaks the albums list. I updated the export_fb.php script to fix this.

Permissions: Yes, it's using 'guest' to list albums & photos.

The app is not showing in FB application directory because it has not been reviewed by FB yet. It's a long process. It will appear under Photos once it's approved.

- Guillaume Boudreau

 
sunnychan

Joined: 2007-06-08
Posts: 5
Posted: Mon, 2007-06-18 21:26

Yes you can. Using the call fetch-album-images, the reply should have image.title.ref-num, etc. G2 has a slightly different interface though.

 
myobie

Joined: 2006-05-30
Posts: 18
Posted: Tue, 2007-06-19 09:55

hey man!

you are a legend.. working sweet now.

FYI: it doesnt work for multisite.
this would break it:
require_once(dirname(__FILE__) . '/../bootstrap.inc');
require_once(dirname(__FILE__) . '/../init.inc');

only have config, embed, index and main.php files in root gallery folder w a multisite install.
would be nice.. but no worries :)

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Wed, 2007-06-20 23:17
myobie wrote:
FYI: it doesnt work for multisite.

Fixed. Re-download the export_fb.php script and put it in a 'fb' directory in your multisite install and it should work just fine now.

- Guillaume Boudreau

 
stephen_pain

Joined: 2007-06-26
Posts: 2
Posted: Tue, 2007-06-26 18:11

very nice - thanks for the plugin :)

I noticed that the browser status bar says "waiting for gallery.dansleresau.com" all the time it's processing the imports... it doesn't bother me, particularly, but it would be interesting to know what this is doing?

Thanks again

Stephen

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Wed, 2007-06-27 00:51

The FB application is on that server. Facebook applications are remote applications, and in this case, simply use an IFRAME to show the web pages on my server, thus why your browser says it's loading that URL.

- Guillaume Boudreau

 
stephen_pain

Joined: 2007-06-26
Posts: 2
Posted: Wed, 2007-06-27 07:09

Thanks for the explanation.

Stephen

 
neil1228

Joined: 2005-08-12
Posts: 18
Posted: Wed, 2007-06-27 09:00

Does the facebook development platform provide for a way to import photos from facebook into gallery (basically the opposite of what this app does)? Many of my users are looking for a way to export their photos out of facebook and into gallery.

 
gboudreau
gboudreau's picture

Joined: 2006-10-01
Posts: 40
Posted: Wed, 2007-06-27 10:22

Yes. facebook.photos.get will return URLs to photos in Facebook, so you could use that to import FB photos in Gallery.

- Guillaume Boudreau

 
shazde7

Joined: 2007-06-28
Posts: 1
Posted: Thu, 2007-06-28 05:07

Sorry for posting something irrelevant guys, but I am new to facebook apps. I am trying to create that sample application that facebook has.

in my server directory, I have the following files:
appinclude.php , index.php , facebookapi_php5_restlib.php , facebook.php

----------------------------------
this is what I have inside index php:

<?php
require_once 'appinclude.php';

echo "<p>hello $user</p>";
-------------------------------------

this is appinclude.php:

<?php
require_once 'facebook.php';

$appapikey = 'I put my key here';
$appsecret = 'and secret here';
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login();

//[todo: change the following url to your callback url]
$appcallbackurl = 'http://www.shervin.copperstream.co.uk/shaheen/';

//catch the exception that gets thrown if the cookie has an invalid session_key in it
try {
if (!$facebook->api_client->users_isAppAdded()) {
$facebook->redirect($facebook->get_add_url());
}
} catch (Exception $ex) {
//this will clear cookies for your app and redirect them to a login prompt
$facebook->set_user(null, null);
$facebook->redirect($appcallbackurl);
}
------------------------------------------------------------------

so this is my call back url : http://www.shervin.copperstream.co.uk/shaheen/

and this is my canvas page: http://apps.facebook.com/shaheentest

side nav url : http://apps.facebook.com/shaheentest/index.php/

-----------------------------------------------------------------

However, when I try to add the application, I receive this error message:

The URL http://www.shervin.copperstream.co.uk/shaheen/index.php/?auth_token=023587bac7913619fe08d043ec11c99b&installed=1 did not respond

Could you please help me? I think you can probably spot the error in 2 seconds, but I'm a complete newbie.

Thanks.

 
osbourd2

Joined: 2005-07-15
Posts: 8
Posted: Mon, 2007-07-02 08:31

Is there a way of including a random image from Gallery in my FB profile? I don't really want to import everything to FB, although I can see the benefit of being able to tag the images etc.

 
petterviken
petterviken's picture

Joined: 2007-04-25
Posts: 9
Posted: Tue, 2007-07-10 08:30

(YEAY! I've been looking for something like this for a looong time! so when i did my routine 'facebook' search-entry here after i came home from vacation a lot seemed to have happened... anyway...)

I'm with 'rhughes2270': i don't want all my 1200 pictures from my gallery in FB. i dont like storing the same thing 2 places (and allso: upploading my pictures to FB gives FB all the rights to ALL the pictures from my gallery. for eternity!).

so what i need is almost like RSS feed, but much fancier of course, on my FB-profile. since i'm not that computer skilled, I'm wondering if there is a "finished product" out there i can just install on my FB-profile?