Advertisement
JakRapp

Instagram Photos to Facebook

Sep 9th, 2016
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. <?php
  2.     /* 2015 (c) dwi-siswant0.blogspot.com */
  3.     // recommend for trig; 5 minutes
  4.  
  5. $token = array(
  6.     "ig" => "...", // access token Instagram Anda
  7.     "fb" => "..." // access token Facebook Anda
  8. );
  9.  
  10. $sopo = array(
  11.     // kumpulan username Instagram target yang ingin ditransfer fotonya ke Facebook (secara acak)
  12.     "jakrapp_",
  13.     "lovianadr2",
  14.     "official_lexsugar18",
  15.     "kacungguyon",
  16.     "qoutespict",
  17.     "memecomicindonesia",
  18.     "parodi.seru"
  19. );
  20.  
  21. function hajar($yuerel, $dataAing=null) {
  22.     $cuih = curl_init();
  23.     curl_setopt($cuih, CURLOPT_URL, $yuerel);
  24.     if($dataAing != null){
  25.         curl_setopt($cuih, CURLOPT_POST, true);
  26.         curl_setopt($cuih, CURLOPT_POSTFIELDS, $dataAing);
  27.     }
  28.     curl_setopt($cuih, CURLOPT_FOLLOWLOCATION, true);
  29.     curl_setopt($cuih, CURLOPT_RETURNTRANSFER, true);
  30.     curl_setopt($cuih, CURLOPT_SSL_VERIFYPEER, false);
  31.     $eks = curl_exec($cuih);
  32.     curl_close($cuih);
  33.     return $eks;
  34. }
  35.  
  36. function search($user) {
  37.     global $token;
  38.     echo "=> Getting account : ";
  39.     $cari = json_decode(hajar("https://api.instagram.com/v1/users/search?q=" . $user . "&access_token=" . $token['ig']), true);
  40.     if ($cari['meta']['code'] == 200 && (isset($cari['data'][0]['username']))) {
  41.         echo "OK!";
  42.         echo "\nUname: " . $cari['data'][0]['username'];
  43.         echo "\nUID: " . $cari['data'][0]['id'] . "\n\n";
  44.         return $cari;
  45.     } else {
  46.         echo "ERROR!\n";
  47.         echo "Failed when getting Instagram account you want to transfer, please check the list of accounts.";
  48.         exit;
  49.     }
  50. }
  51.  
  52. function fetch() {
  53.     global $token, $sopo;
  54.     $cari = search($sopo[array_rand($sopo)]);
  55.     echo "=> Fetch a photo : ";
  56.     $fetch = json_decode(hajar("https://api.instagram.com/v1/users/" . $cari['data'][0]['id'] . "/media/recent?count=1&access_token=" . $token['ig']), true);
  57.     if ($fetch['data'][0]['type'] == "image" && $cari['meta']['code'] == 200) {
  58.         echo "OK!\n";
  59.         echo "Link: " . $fetch['data'][0]['link'];
  60.         echo "\nCaption: " . $fetch['data'][0]['caption']['text'];
  61.         echo "\nID: " . $fetch['data'][0]['id'] . "\n\n";
  62.         return $fetch;
  63.     } elseif (isset($fetch['meta']['error_type'])) {
  64.         echo "Something error.\n";
  65.         echo $fetch['meta']['error_message'];
  66.         exit;
  67.     }
  68. }
  69.  
  70. $ambil = fetch();
  71. echo "=> Post to Facebook : ";
  72. $kirim = json_decode(hajar("https://graph.facebook.com/me/photos", array(
  73.     "message" => $ambil['data'][0]['caption']['text'],
  74.     "url" => $ambil['data'][0]['images']['standard_resolution']['url'],
  75.     "access_token" => $token['fb'])
  76. ), true);
  77.  
  78. if (isset($kirim['post_id'])) {
  79.     echo "OK!";
  80.     echo "\nPID: " . $kirim['post_id'];
  81. } elseif (isset($kirim['error'])) {
  82.     echo "ERROR!\n";
  83.     echo $kirim['error']['message'];
  84. } else {
  85.     echo "ERROR!";
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement