{"id":1733,"date":"2010-09-03T17:23:53","date_gmt":"2010-09-03T16:23:53","guid":{"rendered":"http:\/\/www.nivas.hr\/blog\/?p=1733"},"modified":"2011-03-02T11:28:45","modified_gmt":"2011-03-02T10:28:45","slug":"facebook-php-sdk-access-token-signing-bug","status":"publish","type":"post","link":"https:\/\/www.nivas.hr\/blog\/2010\/09\/03\/facebook-php-sdk-access-token-signing-bug\/","title":{"rendered":"Facebook PHP SDK access token signing bug"},"content":{"rendered":"<p>So if you are getting <\/p>\n<blockquote><p>The method you are calling or the FQL table you are querying cannot be called using a session secret or by a desktop application.<\/p><\/blockquote>\n<p> while trying to run some old facbook REST API while using new <a href=\"http:\/\/github.com\/facebook\/php-sdk\">php sdk<\/a> this post is for you!<\/p>\n<p>Truth is the some REST calls dose not have new graph equivalent. Like for example <strong>dashboard.addGlobalNews<\/strong>. <\/p>\n<p>SDK even in new 2.1.1. version still dose not know how to sign old REST api calls. <\/p>\n<p>When making a call SDK internally calls <strong>getAccessToken<\/strong> method to get token.<br \/>\nIf you mix new graph api with old REST api internal check for type of api message signing will go havoc.<\/p>\n<p>So quick and dirty solution, add override to facebook SDK and thank them for making it open source. <\/p>\n<p>Add this property to facebook sdk class:<\/p>\n<p><code><br \/>\npublic $overrideToAppSigned = false;<br \/>\n<\/code><br \/>\nand change getAccessToken method to:<br \/>\n<code><br \/>\npublic function getAccessToken() {<br \/>\n    $session = $this-&gt;getSession();<br \/>\n    \/\/ either user session signed, or app signed<br \/>\n    if ($session &amp;&amp; !$this-&gt;overrideToAppSigned) {<br \/>\n      return $session['access_token'];<br \/>\n    } else {<br \/>\n      return $this-&gt;getAppId() .'|'. $this-&gt;getApiSecret();<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><\/p>\n<p>Now you can call old REST api like this:<br \/>\n<code><\/p>\n<p>$this-&gt;_facebook-&gt;overrideToAppSigned = true;<\/p>\n<p>$result = $this-&gt;_facebook-&gt;api(<br \/>\narray(<br \/>\n\t'method' =&gt; 'dashboard.addGlobalNews',<br \/>\n\t'call_id' =&gt; microtime(true),<br \/>\n\t'news' =&gt; $news<br \/>\n)<br \/>\n);<\/p>\n<p>$this-&gt;_facebook-&gt;overrideToAppSigned = false;<\/p>\n<p><\/code><\/p>\n<p>Don&#8217;t forget the last line! ;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So if you are getting The method you are calling or the FQL table you are querying cannot be called using a session secret or by a desktop application. while trying to run some old facbook REST API while using new php sdk this post is for you! Truth is the some REST calls dose&#8230;<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/1733"}],"collection":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/comments?post=1733"}],"version-history":[{"count":13,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/1733\/revisions"}],"predecessor-version":[{"id":1928,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/1733\/revisions\/1928"}],"wp:attachment":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/media?parent=1733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/categories?post=1733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/tags?post=1733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}