{"id":1581,"date":"2022-08-30T15:17:43","date_gmt":"2022-08-30T15:17:43","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/expend-access-token-for-fan-pages-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:43","modified_gmt":"2022-08-30T15:17:43","slug":"expend-access-token-for-fan-pages-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/expend-access-token-for-fan-pages-collection-of-common-programming-errors\/","title":{"rendered":"Expend access token for fan pages-Collection of common programming errors"},"content":{"rendered":"<p>i searched for 2 days about my problem find a lot of solution but none worked for me. I want to make a facebook application that i will access from cronjob once for 20 minutes. This app shoult post to my page a photo with description in a album. The problem is the token access that expires &#8230; so the code &#8230;<\/p>\n<pre><code>\/\/connect to api\n$facebook = new Facebook(array(\n          'appId'  =&gt; APP_ID,\n          'secret' =&gt; APP_SECRET\n        ));\n\n\/\/get the page token\n$page_id = 222506244512259;\n$page_info = $facebook-&gt;api(\"\/$page_id?fields=access_token\");\n\n$page_info['access_token']; \/\/so if i use this token is ok but it expires in 2 hours\n\n\/\/now we try to use something else to extend the time\n\n$token_url=\"https:\/\/graph.facebook.com\/oauth\/access_token?client_id=\".APP_ID.\"&amp;client_secret=\".APP_SECRET.\"&amp;grant_type=fb_exchange_token&amp;fb_exchange_token=\".$facebook-&gt;getAccessToken();\n\n\/\/so if i use this formula i will receive a token that never expires, is ok but if I try to use the acces token for posting it doesn work is not valid\n\n$response = file_get_contents($token_url);\n$params = null;\nparse_str($response, $params);\n$page_info['access_token'] = $params['access_token'];\n\n\n\/\/and this is the rest code for posting\n\n$image['file'] = 'images\/rezultate\/'.$link;\n$args = array( 'access_token' =&gt; $page_info['access_token'], 'message' =&gt; ':-)<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-27 11:53:31. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>i searched for 2 days about my problem find a lot of solution but none worked for me. I want to make a facebook application that i will access from cronjob once for 20 minutes. This app shoult post to my page a photo with description in a album. The problem is the token access [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1581","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1581"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1581\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}