简体   繁体   中英

video upload using facebook api

This is the code that i found and run for uploading videos in Facebook using API.

<?php
     $app_id = "******";
     $app_secret = "******";
     $my_url = "http://www.someurl.com/testing/2015/fbtest/4.php";
     $video_title = "video";
     $video_desc = "nothing";
     $page_id = "********"; 

     $code = isset($_REQUEST['code']) ? $_REQUEST['code'] : NULL;

     echo '<html><body>';

    if(empty($code)) {

    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=".$app_id . "&redirect_uri=" . urlencode($my_url)
  . "&scope=publish_actions";
   echo('<script>top.location.href="' . $dialog_url . '";</script>');
   } else {


  $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);

   $resp_obj = json_decode($response,true);
   $accounts = $resp_obj['data'];


   foreach($accounts as $account) {
   if($account['id'] == $page_id) {
     $access_token = $account['access_token'];
     break;
   }
   }


     $post_url = "https://graph-video.facebook.com/" . $page_id . "/videos?"
  . "title=" . $video_title. "&description=" . $video_desc
  . "&access_token=". $access_token;


   echo '<form enctype="multipart/form-data" action=" '.$post_url.' "  
   method="POST">';
   echo 'Please choose a file:';
   echo '<input name="file" type="file">';
   echo '<input type="submit" value="Upload" />';
   echo '</form>';
 }

   echo '</body></html>';
   ?>`

When i ran the code I'm getting error like this.

      error": 
     {   
     "message": "Invalid OAuth access token.",  
     "type": "OAuthException",       
     "code": 190
     }

But when i searched for the answer i saw discussions involving including of access key. I don't know where to change my code or is there any other possible solutions to this error.

To fix this problem you need to have OAuth athentication in your app. Here is the official page, which explain the protocol:

Additionally, you can also check the oauth 2.0 demos and information for PHP:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM