Created
November 8, 2012 21:12
-
-
Save ptasker/4041640 to your computer and use it in GitHub Desktop.
Facebook JS SDK API - Post Image to Feed
This file contains hidden or 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 share_image(img_url, text) { | |
| //Check to see if the user has authenticated the App. | |
| FB.getLoginStatus(function(response) { | |
| if (response.status === 'connected') { | |
| //If you want the user's Facebook ID or their access token, this is how you get them. | |
| var uid = response.authResponse.userID; | |
| var access_token = response.authResponse.accessToken; | |
| do_api_share(access_token, img_url, text); | |
| } else { | |
| //If they haven't, call the FB.login method | |
| FB.login(function(response) { | |
| if (response.authResponse) { | |
| //If you want the user's Facebook ID or their access token, this is how you get them. | |
| var uid = response.authResponse.userID; | |
| var access_token = response.authResponse.accessToken; | |
| do_api_share(access_token, img_url, text); | |
| } else { | |
| alert("You must install the application to share your greeting."); | |
| } | |
| }, {scope: 'publish_stream'}); | |
| } | |
| }); | |
| } | |
| function do_api_share(at, img_url, text) { | |
| FB.api("/me/photos", 'post', { message: text, url: img_url}, function(response) { | |
| console.log(response); | |
| }); | |
| } | |
| //Calling the function | |
| share_img("http://example.com/images/image-one.jpg", "Hi there!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment