Created
August 2, 2012 19:18
-
-
Save fideloper/3239870 to your computer and use it in GitHub Desktop.
Facebook Code Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Note that this does not use app icons or links in Timeline post. Some messaging is therefor lost. | |
*/ | |
require 'fb/src/facebook.php'; | |
$facebook = new Facebook(array( | |
'appId' => 'SOME_APP_ID', | |
'secret' => 'SOME_APP_SECRET', | |
'fileUpload' => true | |
)); | |
// Get User ID | |
$user = $facebook->getUser(); | |
if($user) { | |
try { | |
$result = $facebook->api('/me/photos', 'POST', array( | |
'image' => '@'.realpath('./server_path_to_image_file.jpg'), | |
'name' => 'A caption to use for image messaging' | |
)); | |
} catch(FacebookApiException $e) { | |
die($e->getMessage()); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Facebook() { | |
var _this = this; | |
/** | |
* Share current page data to current users Timeline | |
* Image URL is the URL to an image, not an HTML page | |
* Other implementations have the object be a url leading to an HTML page | |
* with <meta property="og:some_object" content="http://example.com/some_object" /> | |
* and other og meta tags | |
*/ | |
this.fbShare = function(object, imageUrl, mssg, next) { | |
FB.api( | |
'/me/app_name_space:some_action?some_object='+object+'&image[0][url]='+imageUrl+'&image[0][user_generated]=true', | |
'POST', | |
{message: _this._clean(mssg)}, | |
function(response) { | |
if (!response || response.error) { | |
//alert('Error occured'); | |
if(_debug) { console.log(response.error); } | |
if(typeof next === 'function') { | |
next(true, null); | |
} | |
} else { | |
if(_debug) { console.log('shared'); } | |
//Change views here | |
if(typeof next === 'function') { | |
next(false, response.id); | |
} | |
} | |
} | |
); | |
} | |
/** | |
* Clean user input | |
* a) Strip tags | |
* b) Add slashes to single quotes - REMOVED FOR NOW | |
*/ | |
this._clean = function(str) { | |
if(str !== '') { | |
str = str.replace(/(<([^>]+)>)/ig,""); | |
//str = str.replace("'", "\'"); | |
return str; | |
} | |
return ''; | |
} | |
}//end facebook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment