{"id":462,"date":"2012-03-30T15:59:58","date_gmt":"2012-03-30T15:59:58","guid":{"rendered":"http:\/\/corbdesign.com\/blog\/?p=462"},"modified":"2012-03-30T15:59:58","modified_gmt":"2012-03-30T15:59:58","slug":"getting-fb-access-token","status":"publish","type":"post","link":"https:\/\/corbinrose.com\/blog\/technology\/getting-fb-access-token\/","title":{"rendered":"Getting FB access token"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"post-1486\">Facebook Graph API \u2014 getting access tokens<\/h2>\n\n\n\n<p><em>completely &#8220;borrowed&#8221; from&nbsp;<a href=\"http:\/\/benbiddington.wordpress.com\/2010\/04\/23\/facebook-graph-api-getting-access-tokens\/\" target=\"_blank\" rel=\"noopener noreferrer\">this site<\/a><\/em><\/p>\n\n\n\n<div>\n<p>Assume an application with an id&nbsp;<em>116122545078207<\/em>, and using the URL of the blog (http:\/\/benbiddington.wordpress.com) to collect request tokens.<\/p>\n<p>Following the instructions as specified in section&nbsp;<em>3.5.1.1., Client Requests Authorization,<\/em>&nbsp;of the&nbsp;<a href=\"http:\/\/tools.ietf.org\/html\/draft-ietf-oauth-v2-05#section-3.5.2\" target=\"_blank\" rel=\"noopener noreferrer\">specification<\/a>, this is a one-step process:<\/p>\n<p>Open this in a browser:<\/p>\n<pre style=\"position: relative;\">https:\/\/graph.facebook.com\/oauth\/authorize?\n    type=user_agent&amp;\n    client_id=116122545078207&amp;\n    redirect_uri=http%3A%2F%2Fbenbiddington.wordpress.com&amp;\n    scope=user_photos,email,user_birthday,user_online_presence<\/pre>\n<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/div>\n<p>Note: there are several options for scope. These are called&nbsp;<a href=\"http:\/\/developers.facebook.com\/docs\/authentication\/permissions\" target=\"_blank\" rel=\"noopener noreferrer\">extended permissions<\/a>.<\/p>\n<p>Note: unless you specify&nbsp;<strong>offline_access<\/strong>, your tokens will expire as soon as the user signs out of facebook.<\/p>\n<p>Note:&nbsp;<em>client_secret<\/em>&nbsp;is not supplied:<\/p>\n<blockquote><p>[<a href=\"http:\/\/tools.ietf.org\/html\/draft-ietf-oauth-v2-05#section-3.5.2\" target=\"_blank\" rel=\"noopener noreferrer\">3.5.1. &nbsp;User-Agent Flow<\/a>] This user-agent flow does not utilize the client secret since the client executables reside on the end user\u2019s computer or device which makes the client secret accessible and exploitable.<\/p><\/blockquote>\n<p>You\u2019ll be redirected to:<\/p>\n<pre style=\"position: relative;\">http:\/\/benbiddington.wordpress.com\/#access_token=\n    116122545078207|\n    2.1vGZASUSFMHeMVgQ_9P60Q__.3600.1272535200-500880518|\n    QXlU1XfJR1mMagHLPtaMjJzFZp4.<\/pre>\n<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/div>\n<p>And you have your access token, you can go ahead and use it:<\/p>\n<pre style=\"position: relative;\">https:\/\/graph.facebook.com\/me?access_token=\n    116122545078207|\n    2.1vGZASUSFMHeMVgQ_9P60Q__.3600.1272535200-500880518|\n    QXlU1XfJR1mMagHLPtaMjJzFZp4.<\/pre>\n<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/div>\n<p>According to section&nbsp;<em><a href=\"http:\/\/tools.ietf.org\/html\/draft-ietf-oauth-v2-05#section-3.5.2\" target=\"_blank\" rel=\"noopener noreferrer\">3.5.1. Client Requests Authorization<\/a><\/em>, because we have not supplied the optional<em>secret_type:<\/em><\/p>\n<pre style=\"position: relative;\">secret_type\n    OPTIONAL. The access token secret type as described by \n    Section 5.3. If omitted, the authorization server will issue\n    a bearer token (an access token without a matching secret) \n    as described by Section 5.2.<\/pre>\n<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/div>\n<p><\/p>\n<h3><strong>What can you do with the graph?<\/strong><\/h3>\n<p>Borrowed from&nbsp;<a href=\"https:\/\/developers.facebook.com\/docs\/reference\/api\/\">https:\/\/developers.facebook.com\/docs\/reference\/api\/<\/a><\/p>\n<p>At Facebook&#8217;s core is the social graph; people and the connections they have to everything they care about. The Graph API presents a simple, consistent view of the Facebook social graph, uniformly representing objects in the graph (e.g.,&nbsp;<a href=\"https:\/\/developers.facebook.com\/docs\/reference\/api\/user\">people<\/a>,&nbsp;<a href=\"https:\/\/developers.facebook.com\/docs\/reference\/api\/photo\">photos<\/a>,&nbsp;<a href=\"https:\/\/developers.facebook.com\/docs\/reference\/api\/event\">events<\/a>, and&nbsp;<a href=\"https:\/\/developers.facebook.com\/docs\/reference\/api\/page\">pages<\/a>) and the connections between them (e.g., friend relationships, shared content, and photo tags).<\/p>\n<p>Every object in the social graph has a unique ID. You can access the properties of an object by requesting<\/p>\n<pre style=\"position: relative;\">https:\/\/graph.facebook.com\/ID<\/pre>\n<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/div>\n<p>. For example, the official page for the&nbsp;<a href=\"https:\/\/www.facebook.com\/platform\">Facebook Platform<\/a>&nbsp;has id 19292868552, so you can fetch the object at&nbsp;<a href=\"https:\/\/graph.facebook.com\/19292868552\">https:\/\/graph.facebook.com\/19292868552<\/a>:<\/p>\n<pre style=\"position: relative;\">{ \n\"name\": \"Facebook Platform\", \n\"website\": \"http:\/\/developers.facebook.com\", \n\"username\": \"platform\", \"founded\": \"May 2007\", \n\"company_overview\": \"Facebook Platform enables anyone to build...\",\n \"mission\": \"To make the web more open and social.\",\n \"products\": \"Facebook Application Programming Interface (API)...\",\n \"likes\": 449921,\n \"id\": 19292868552,\n \"category\": \"Technology\" \n}<\/pre>\n<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/div>\n<p>Alternatively, people and pages with usernames can be accessed using their username as an ID. Since &#8220;platform&#8221; is the username for the page above,&nbsp;<a href=\"https:\/\/graph.facebook.com\/platform\">https:\/\/graph.facebook.com\/platform<\/a>&nbsp;will return what you expect. All responses are JSON objects.<\/p>\n<p>All objects in Facebook can be accessed in the same way:<\/p>\n<ul>\n<li>Users:&nbsp;<a href=\"https:\/\/graph.facebook.com\/btaylor\">https:\/\/graph.facebook.com\/btaylor<\/a>&nbsp;(Bret Taylor)<\/li>\n<li>Pages:&nbsp;<a href=\"https:\/\/graph.facebook.com\/cocacola\">https:\/\/graph.facebook.com\/cocacola<\/a>&nbsp;(Coca-Cola page)<\/li>\n<li>Events:&nbsp;<a href=\"https:\/\/graph.facebook.com\/331218348435\">https:\/\/graph.facebook.com\/251906384206<\/a>&nbsp;(Facebook Developer Garage Austin)<\/li>\n<li>Groups:&nbsp;<a href=\"https:\/\/graph.facebook.com\/195466193802264\">https:\/\/graph.facebook.com\/195466193802264<\/a>&nbsp;(Facebook Developers group)<\/li>\n<li>Applications:&nbsp;<a href=\"https:\/\/graph.facebook.com\/2439131959\">https:\/\/graph.facebook.com\/2439131959<\/a>&nbsp;(the Graffiti app)<\/li>\n<li>Status messages:&nbsp;<a href=\"https:\/\/graph.facebook.com\/367501354973?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/367501354973<\/a>&nbsp;(A status message from Bret)<\/li>\n<li>Photos:&nbsp;<a href=\"https:\/\/graph.facebook.com\/98423808305\">https:\/\/graph.facebook.com\/98423808305<\/a>&nbsp;(A photo from the Coca-Cola page)<\/li>\n<li>Photo albums:&nbsp;<a href=\"https:\/\/graph.facebook.com\/99394368305\">https:\/\/graph.facebook.com\/99394368305<\/a>&nbsp;(Coca-Cola&#8217;s wall photos)<\/li>\n<li>Profile pictures:&nbsp;<a href=\"https:\/\/graph.facebook.com\/100003282441198\/picture\">https:\/\/graph.facebook.com\/100003282441198\/picture<\/a>&nbsp;(your profile picture)<\/li>\n<li>Videos:&nbsp;<a href=\"https:\/\/graph.facebook.com\/817129783203?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/817129783203<\/a>&nbsp;(A Facebook tech talk on Graph API)<\/li>\n<li>Notes:&nbsp;<a href=\"https:\/\/graph.facebook.com\/122788341354?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/122788341354<\/a>&nbsp;(Note announcing Facebook for iPhone 3.0)<\/li>\n<li>Checkins:&nbsp;<a href=\"https:\/\/graph.facebook.com\/414866888308?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/414866888308<\/a>&nbsp;(Check-in at a pizzeria)<\/li>\n<\/ul>\n<p>All of the objects in the Facebook social graph are connected to each other via relationships. Bret Taylor is a fan of the Coca-Cola page, and Bret Taylor and Arjun Banker are friends. We call those relationships&nbsp;<em>connections<\/em>&nbsp;in our API. You can examine the connections between objects using the URL structure<\/p>\n<pre style=\"position: relative;\">https:\/\/graph.facebook.com\/ID\/CONNECTION_TYPE<\/pre>\n<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/div>\n<p>. The connections supported for people and pages include:<\/p>\n<ul>\n<li>Friends:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/friends?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>friends<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>News feed (this is an outdated view, does not reflect the News Feed on facebook.com):<a href=\"https:\/\/graph.facebook.com\/me\/home?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>home<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Profile feed (Wall):&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/feed?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>feed<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Likes:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/likes?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>likes<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Movies:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/movies?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>movies<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Music:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/music?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>music<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Books:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/books?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>books<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Notes:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/notes?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>notes<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Permissions:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/permissions?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>permissions<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Photo Tags:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/photos?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>photos<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Photo Albums:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/albums?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>albums<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Video Tags:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/videos?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>videos<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Video Uploads:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/videos\/uploaded?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>videos\/uploaded<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Events:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/events?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>events<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Groups:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/groups?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>groups<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Checkins:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/checkins?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>checkins<\/strong>?access_token=&#8230;<\/a><\/li>\n<li>Objects with Location:&nbsp;<a href=\"https:\/\/graph.facebook.com\/me\/locations?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/me\/<strong>locations<\/strong>?access_token=&#8230;<\/a><\/li>\n<\/ul>\n<p>We support different connection types for different objects. For example, you can get the list of all the people attending the Facebook Developer Garage at SXSW (ID #331218348435) by fetching<a href=\"https:\/\/graph.facebook.com\/331218348435\/attending?access_token=AAAAAAITEghMBAF8BJy9lNfqzrh5ClMVVVF0wZCZAvNFEpjmzK8lchoJ8iWsZCQFK9DIIOW6lR2ZB0N3cKd05AQ7vnmSss927bqg6y7nf3UwO3pbfaUHo\">https:\/\/graph.facebook.com\/331218348435\/<strong>attending<\/strong>?access_token=&#8230;<\/a>.<\/p>\n<p>All of the different types of objects and connections we support are included in the&nbsp;<a href=\"https:\/\/developers.facebook.com\/docs\/reference\/api\/\">Graph API reference documentation<\/a>. The easiest way to get started is to check out the&nbsp;<a href=\"https:\/\/developers.facebook.com\/tools\/explorer\">Graph API Explorer<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Facebook Graph API \u2014 getting access tokens completely &#8220;borrowed&#8221; from&nbsp;this site Assume an application with an id&nbsp;116122545078207, and using the URL of the blog (http:\/\/benbiddington.wordpress.com) to collect request tokens. Following the instructions as specified in section&nbsp;3.5.1.1., Client Requests Authorization,&nbsp;of the&nbsp;specification, this is a one-step process: Open this in a browser: https:\/\/graph.facebook.com\/oauth\/authorize? type=user_agent&amp; client_id=116122545078207&amp; redirect_uri=http%3A%2F%2Fbenbiddington.wordpress.com&amp; scope=user_photos,email,user_birthday,user_online_presence [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":4912,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[28,17],"tags":[],"class_list":["post-462","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-technology","clearfix","post-index"],"acf":[],"jetpack_featured_media_url":"https:\/\/corbinrose.com\/blog\/wp-content\/uploads\/2012\/03\/pexels-photo-267399-1.jpeg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":0,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/media\/4912"}],"wp:attachment":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}