Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2. $app_id = "23***************";
  3. $app_secret = "******************";
  4. $my_url = "http://localhost/fbupload/";
  5. $video_title = "Test";
  6. $video_desc = "Test";
  7.  
  8. $code = $_REQUEST["code"];
  9.  
  10. if(empty($code)) {
  11. $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
  12. . $app_id . "&redirect_uri=" . urlencode($my_url)
  13. . "&scope=publish_stream";
  14. echo("<script>top.location.href='" . $dialog_url . "'</script>");
  15. }
  16.  
  17. $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
  18. . $app_id . "&redirect_uri=" . urlencode($my_url)
  19. . "&client_secret=" . $app_secret
  20. . "&code=" . $code;
  21. $access_token = file_get_contents($token_url);
  22.  
  23. $post_url = "https://graph-video.facebook.com/me/videos?"
  24. . "title=" . $video_title. "&description=" . $video_desc
  25. . "&". $access_token;
  26.  
  27. //CURL CODES START
  28.  
  29. $ch = curl_init();
  30. $data = array('name' => 'file', 'file' => '@/1.mp4');
  31. curl_setopt($ch, CURLOPT_URL, $post_url);
  32. curl_setopt($ch, CURLOPT_POST, 1);
  33. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  34. curl_exec($ch);
  35.  
  36. //CURL ENDS
  37. ?>
  38.  
  39. echo '<form enctype="multipart/form-data" action="'.$post_url.'
  40. "method="POST">';
  41. echo 'Please choose a file:';
  42. echo '<input name="file" type="file">';
  43. echo '<input type="submit" value="Upload" />';
  44. echo '</form>';
  45.  
  46. <?php
  47. $app_id = "XXXXXXXXXXXXXXXx";
  48. $app_secret = "XXXXXXXXXXXXXXXxx";
  49. $my_url = "YOUR_URL_HERE";
  50. $video_title = "Test";
  51. $video_desc = "Test";
  52.  
  53. $code = $_REQUEST["code"];
  54.  
  55. if(empty($code)) {
  56. $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
  57. . $app_id . "&redirect_uri=" . urlencode($my_url)
  58. . "&scope=publish_actions";
  59. echo("<script>top.location.href='" . $dialog_url . "'</script>");
  60. }
  61.  
  62. $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
  63. . $app_id . "&redirect_uri=" . urlencode($my_url)
  64. . "&client_secret=" . $app_secret
  65. . "&code=" . $code;
  66. $access_token = file_get_contents($token_url);
  67.  
  68. $post_url = "https://graph-video.facebook.com/me/videos?"
  69. . "title=" . $video_title. "&description=" . $video_desc
  70. . "&". $access_token;
  71.  
  72. //CURL CODES START
  73.  
  74. $ch = curl_init();
  75. $data = array('name' => 'file', 'file' => '@'.realpath("sample_mpeg4.mp4"));// use realpath
  76. curl_setopt($ch, CURLOPT_URL, $post_url);
  77. curl_setopt($ch, CURLOPT_POST, 1);
  78. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  79. $res = curl_exec($ch);
  80.  
  81. if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
  82. curl_setopt($ch, CURLOPT_CAINFO,
  83. dirname(__FILE__) . '/src/fb_ca_chain_bundle.crt'); // path to the certificate
  84. $res = curl_exec($ch);
  85. }
  86.  
  87. if( $res === false ) {
  88. echo curl_error($ch);
  89. }
  90. curl_close($ch);
  91.  
  92. //CURL ENDS
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement