php script facebook (#100) No permission to publish the video -
i'm trying upload video on facebook page using code. have added compulsory credentials add video. when select video , click upload button json request says dont have permission upload video. tried debug problem couldn't succeed. please me out. thank you
<?php $app_id = "xxxxxxxxxxxxxxx"; $app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $my_url = "http://xxxxxxxx/test.php"; $video_title = "test_video_for_app"; $video_desc = "test_description"; $page_id = "xxxxxxxxxxxxxxxx"; // set app_id applications $code = $_request["code"]; echo '<html><body>'; if(empty($code)) { // permission user publish page. $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id . "&redirect_uri=" . urlencode($my_url). "&scope=publish_actions,manage_pages"; echo('<script>top.location.href="' . $dialog_url . '";</script>'); } else { // access token user, can /me/accounts $token_url = "https://graph.facebook.com/oauth/access_token?client_id=". $app_id . "&redirect_uri=" . urlencode($my_url). "&client_secret=" . $app_secret. "&code=" . $code; $access_token = file_get_contents($token_url); $accounts_url = "https://graph.facebook.com/me/accounts?" . $access_token; $response = file_get_contents($accounts_url); // parse return value , array of accounts have // access to. returned in data[] array. $resp_obj = json_decode($response,true); $accounts = $resp_obj['data']; // find access token page want post video. foreach($accounts $account) { if($account['id'] == $page_id) { $access_token = $account['access_token']; break; } } // using page access token above, create post action // our form use upload video. $post_url = "https://graph-video.facebook.com/" . $page_id . "/videos?". "title=" . $video_title. "&description=" . $video_desc. "&access_token=". $access_token; // create simple form echo '<form enctype="multipart/form-data" action=" '.$post_url.' " method="post">'; echo 'please choose file:'; echo '<input name="file" type="file">'; echo '<input type="submit" value="upload" />'; echo '</form>'; } echo '</body></html>'; ?>
this responce coming facebook
{ "error": { "message": "(#100) no permission publish video", "type": "oauthexception", "code": 100, "fbtrace_id": "h1uof8k83ll" } }
so after long research got solution. need add permission developers.facebook.com.
- fisrt go developers.facebook.com
- go tools , support , select graph api explorer
- then select application , click on access token
- add permission publish_action in , click ok
- u access token.
copy thataccess token , paste in place of
$access_token = file_get_contents($token_url);
it like
$access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
then run code , done
Comments
Post a Comment