Guest User

Código publicacao

a guest
Jan 25th, 2014
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. require 'facebook-php-sdk-master/src/facebook.php';
  3.  
  4.  
  5. $facebook = new Facebook(array(
  6. 'appId' => 'x',
  7. 'secret' => 'x',
  8. ));
  9.  
  10. $APP_ID = "x";
  11. $SECRET = "x";
  12. $PERMS = "publish_stream";
  13.  
  14.  
  15. $facebook = new Facebook(array(
  16. 'appId' => $APP_ID,
  17. 'secret' => $SECRET,
  18. ));
  19.  
  20. $servidor = "xxxx";
  21.  
  22. $usuario = "x";
  23. $senha = "x";
  24. $banco = "aplicativo_facebook";
  25.  
  26. $conexao = mysql_connect($servidor,$usuario,$senha); /*Conecta no bando
  27.  
  28. de dados MySql*/
  29.  
  30. mysql_select_db($banco); /*seleciona o banco a ser usado*/
  31.  
  32. $res = mysql_query("select * from usuarios");
  33.  
  34. uma variavel ($res)
  35.  
  36. while($escrever=mysql_fetch_array($res)){
  37.  
  38.  
  39. $my_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  40.  
  41.  
  42. $code = $_REQUEST['code'];
  43. if(empty($code)) {
  44. $dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
  45. . $APP_ID . "&redirect_uri=" . urlencode($my_url)
  46. . "&scope=$PERMS";
  47.  
  48. header("Location: $dialog_url");
  49. exit;
  50. }
  51.  
  52.  
  53. $token_url = "https://graph.facebook.com/oauth/access_token?"
  54. . "client_id=" . $APP_ID . "&redirect_uri=" . urlencode($my_url)
  55. . "&client_secret=" . $SECRET . "&code=" . $code;
  56.  
  57. $response = file_get_contents($token_url);
  58. $params = null;
  59. parse_str($response, $params);
  60.  
  61. $feed_data = array(
  62. "message" => "Youtube",
  63. "name" => "Site do Youtube",
  64. "link" => "http://www.youtube.com",
  65. "caption" => "www.youtube.com",
  66. "access_token" => $params['access_token'],
  67. );
  68.  
  69. try {
  70. $dados = $facebook->api("100006181831470/feed", "post", $feed_data);
  71. echo "Foto publicada com sucesso!";
  72. } catch (Exception $e) {
  73. echo "<pre>";
  74. var_dump($e);
  75. echo "</pre>";
  76. }
  77.  
  78. }
  79.  
  80. mysql_close(conexao);
  81. ?>
RAW Paste Data