{"id":8,"date":"2013-02-07T14:53:00","date_gmt":"2013-02-07T08:53:00","guid":{"rendered":"http:\/\/promincproductions.com\/blog\/?p=8"},"modified":"2014-05-03T09:09:28","modified_gmt":"2014-05-03T03:09:28","slug":"facebook-graph-api","status":"publish","type":"post","link":"https:\/\/promincproductions.com\/blog\/facebook-graph-api\/","title":{"rendered":"Facebook Graph API"},"content":{"rendered":"<p>I&#8217;ve never enjoyed working with Facebook social tools&#8230; &nbsp;The like button alone seems too difficult, all of the app id&#8217;s, authentication, etc. for other functions is confusing to me, etc.<\/p>\n<p>Regardless, a recent application I built needed to be able to share an image on a Facebook Timeline. &nbsp;Going into the project I thought you&#8217;d simply use the like button, it&#8217;ll display the picture and we are all set, right? <\/p>\n<p>Wrong. &nbsp;The Like button merely likes a URL. &nbsp;So within Facebook (News Feed or Timeline) it shows a small thumbnail of the image and, a text description of the Liked URL, and a link back to the page. &nbsp;This is not the experience I&#8217;m looking for.<\/p>\n<p>Instead, I want the image to show, and clicking on the image opens the image viewer. &nbsp;Simple enough, right? Wrong.<\/p>\n<p>In comes the Graph API and me trying to learn how to use it. &nbsp;I started down the path of the PHP API. &nbsp;This was working fine, I could get the image to share, but there were issues in that since PHP is server side, there were&nbsp;multiple&nbsp;page refreshes happening, URL query parameters, etc. &nbsp;The end result of this project is an iFramed page into another site, and so these page refreshes and the URL parameters killed the chances of this happening&#8230;<\/p>\n<p>Back to the drawing board.<\/p>\n<p>Now for where I should have started; the Javascript SDK to access the Graph API. &nbsp;Since this is run client side and involves AJAX this is the right solution for me! &nbsp;Though I think the Facebook&nbsp;documentation&nbsp;leaves A LOT to be desired it did lead me in the right direction and reading a few other random blog posts later I was able to get this all put together.<\/p>\n<p>The first step is to create an App within Facebook. &nbsp;I found this confusing; I don&#8217;t want to have this live within Facebook; it&#8217;s going to live on my website. &nbsp;But since it&#8217;s interacting with the Graph API and posting to Facebook, you need to have a method for it to be authorized through Facebook. &nbsp;That&#8217;s what the App is for. &nbsp;This is all done through the Facebook Developer site.<\/p>\n<p>Because it&#8217;s tied to an App, it allows for users to block posts from this app, etc. &nbsp;It&#8217;s part of Facebook&#8217;s privacy and content control methods is what I&#8217;ve gathered.<\/p>\n<p>The high level thought pattern of my application is this:<br \/>&#8211; Load the Facebook Javascript SDK<br \/>&#8211; User clicks Facebook Share button<br \/>&#8211; Check if they are logged into Facebook. &nbsp;If not, a popup window allows them to log in (Facebook SDK handles this)<br \/>&#8211; Once logged in, they need to accept the terms of the app. &nbsp;In my case, they need to grant access for the app to post on the timeline of the users friends.<br \/>&#8211; After accepting the terms, they are presented with a list of their Facebook friends. &nbsp;I added a jQuery Live Filter function so they can search for a friend by name (rather than scrolling a few hundred friends). &nbsp;I show the friends picture and name.<br \/>&#8211; Clicking on a name (or the users own name) it automatically posts to the users Timeline.<br \/>&#8211; That&#8217;s it!<\/p>\n<p>It&#8217;s a very simple app to the user that is fairly complex on the back end. &nbsp;But it&#8217;s well built and should drive some great interaction.<\/p>\n<p>One check I had to put in place though, is that a Facebook user can set privacy settings to not allow for others to post on their wall. &nbsp;I have a check in place for that as well, which displays a message and brings the user back to their friends list so they can choose someone else if they&#8217;d like.<\/p>\n<p>So this story isn&#8217;t all that technical, and won&#8217;t help you in the actual coding. &nbsp;Sorry. &nbsp;I struggled through it so much that I&#8217;m not sure I&#8217;m a huge amount of help there. &nbsp;And sadly there isn&#8217;t a lot on the internet on how to do such programming that I could find. &nbsp;But what else I feel isn&#8217;t well documented (or is too wordy; I don&#8217;t like reading much&#8230;) is the simple concept on how making Facebook Apps should be done. &nbsp;The basic structure\/workflow is what I was really missing.<\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve never enjoyed working with Facebook social tools&#8230; &nbsp;The like button alone seems too difficult, all of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[10],"tags":[],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-facebook-development"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4BbcR-8","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":1,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}