Пример #1
0
 function PostPhoto()
 {
     if (!isset($_POST['source']) || $_POST['source'] == "") {
         return "Missing required param";
         exit;
     }
     $config = (include "/config.php");
     $fb = new Facebook\Facebook(['app_id' => $config['app_id'], 'app_secret' => $config['app_secret'], 'default_graph_version' => 'v2.4']);
     $check = new TB_Facebook_Check();
     if (!$check->VerifyImagePost($_POST['source'])) {
         return "Post is not valid";
     }
     $data = ['source' => $fb->fileToUpload($_POST['source'])];
     if (isset($_POST['message']) && $_POST['message'] != "") {
         $data['message'] = FilterText($_POST['message']);
     }
     try {
         // Returns a `Facebook\FacebookResponse` object
         $response = $fb->post('/me/photos', $data, $_SESSION['facebook_access_token']);
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         return 'Graph returned an error: ' . $e->getMessage();
         exit;
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         return 'Facebook SDK returned an error: ' . $e->getMessage();
         exit;
     }
     return 'success';
 }
Пример #2
0
<?php

session_start();
require_once __DIR__ . '/facebook/src/Facebook/autoload.php';
$fb = new Facebook\Facebook(['app_id' => '135572810141672', 'app_secret' => '4780932d14d2d74135964d8ab1afb0bc', 'default_graph_version' => 'v2.5']);
$data = ['message' => 'I love going to the beach. Do you love it.', 'source' => $fb->fileToUpload('E:\\www2\\merrychistmas\\photos\\girlxinh.jpg')];
try {
    // Returns a `Facebook\FacebookResponse` object
    $response = $fb->post('/me/photos', $data, $_SESSION['facebook_access_token']);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}
$graphNode = $response->getGraphNode();
echo 'Photo ID: ' . $graphNode['id'];
        // When Graph returns an error
        if ($e->getCode() == 190) {
            unset($_SESSION['facebook_access_token']);
            $helper = $fb->getRedirectLoginHelper();
            $loginUrl = $helper->getLoginUrl('https://apps.facebook.com/APP_NAMESPACE/', $permissions);
            echo "<script>window.top.location.href='" . $loginUrl . "'</script>";
            exit;
        }
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
    try {
        // message must come from the user-end
        $data = ['source' => $fb->fileToUpload(__DIR__ . '/photo.jpg'), 'message' => 'my photo'];
        $request = $fb->post('/me/photos', $data);
        $response = $request->getGraphNode()->asArray();
    } catch (Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
    echo $response['id'];
    // Now you can redirect to another page and use the
    // access token from $_SESSION['facebook_access_token']
} else {
Пример #4
0
 public function fbcallback()
 {
     if (!session_id()) {
         session_start();
     }
     $channel = DB::table('register')->where('id', $_SESSION['id'])->first();
     $channel_selcted = unserialize($channel->channel);
     $channel_fb = array();
     foreach ($channel_selcted as $key => $value) {
         $channel_fb[$key] = '#' . $value;
     }
     $post_channel = implode(' ', $channel_fb);
     $fb = new \Facebook\Facebook(['app_id' => '1657120087884180', 'app_secret' => 'f78f1e597c749d296383fae00132d6be', 'default_graph_version' => 'v2.5']);
     $helper = $fb->getRedirectLoginHelper();
     try {
         $accessToken = $helper->getAccessToken();
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         // When Graph returns an error
         echo 'Graph returned an error: ' . $e->getMessage();
         exit;
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         // When validation fails or other local issues
         echo 'Facebook SDK returned an error: ' . $e->getMessage();
         exit;
     }
     if (isset($accessToken)) {
         // Logged in!
         $_SESSION['facebook_access_token'] = (string) $accessToken;
         // Now you can redirect to another page and use the
         // access token from $_SESSION['facebook_access_token']
         $data = ['message' => '#แจกตั๋วหนังฟรี แค่ร่วมติดตามรายการทีวีที่คุณชื่นชอบที่ http://bit.ly.com @ฉันกำลังติดตาม ' . $post_channel . ' เกาะติดรายการตอนใหม่ ๆ อย่างรวดเร็วได้ที่ VodKA TV
                   App ที่รวบรวมรายการ TV ย้อนหลังเยอะที่สุดในประเทศไทย
                   iOS : goo.gl/tfvqWE
                   Android : goo.gl/RzNXBg', 'source' => $fb->fileToUpload('./assets/img/vodka/vodka.png')];
         try {
             // Returns a `Facebook\FacebookResponse` object
             $response = $fb->post('/me/photos', $data, $_SESSION['facebook_access_token']);
         } catch (Facebook\Exceptions\FacebookResponseException $e) {
             echo 'Graph returned an error: ' . $e->getMessage();
             exit;
         } catch (Facebook\Exceptions\FacebookSDKException $e) {
             echo 'Facebook SDK returned an error: ' . $e->getMessage();
             exit;
         }
         $graphNode = $response->getGraphNode();
         echo 'Photo ID: ' . $graphNode['id'];
     }
     return redirect('thankyou');
 }
<?php

session_start();
require_once 'src/Facebook/autoload.php';
$fb = new Facebook\Facebook(['app_id' => '1659998380882903', 'app_secret' => 'be1c9c368616a2f8252d41208a187046', 'default_graph_version' => 'v2.2']);
$data = ['message' => 'My awesome photo upload example.', 'source' => $fb->fileToUpload('kursi.jpg')];
$helper = $fb->getRedirectLoginHelper();
$accessToken = $helper->getAccessToken();
$token = $accessToken->getValue();
try {
    // Returns a `Facebook\FacebookResponse` object
    $response = $fb->post('/me/photos', $data, $token);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}
$graphNode = $response->getGraphNode();
echo 'Photo ID: ' . $graphNode['id'];
 public function uploadAction()
 {
     session_start();
     include "../include/connexion.php";
     require_once APPLICATION_PATH . '/public/facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.php';
     $fb = new Facebook\Facebook(['app_id' => '959119600818575', 'app_secret' => '9f0062f110ea6d3589e7debcb04c2268', 'default_graph_version' => 'v2.5']);
     if (!isset($_SESSION['token'])) {
         header("Location: /participate");
     } else {
         $fb->setDefaultAccessToken($_SESSION['token']);
     }
     $target_dir = "images/";
     $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
     $uploadOk = 1;
     $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
     $error = 0;
     $error_msg = "";
     if (isset($_POST["submit"])) {
         $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
         if ($check === false) {
             $error_msg = "File is not an image.";
             $error = 1;
         }
     }
     if ($_FILES["fileToUpload"]["size"] > 500000) {
         $error_msg = "Sorry, your file is too large.";
         $error = 1;
     }
     if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
         $error_msg = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
         $error = 1;
     }
     //Vérification de l'existance de l'album
     $_POST["name_album"] = trim($_POST["name_album"]);
     if (empty($_POST["name_album"])) {
         $response = $fb->get('/me/albums?fields=id,can_upload');
         $albums = $response->getGraphEdge()->asArray();
         $albumFacebook = false;
         foreach ($albums as $album) {
             if ($album["id"] == $_POST['album']) {
                 $albumFacebook = true;
                 break;
             }
         }
         if (!$albumFacebook) {
             $error_msg = "L'upload is not allowed in this album.";
             $error = 1;
         }
     } else {
         $data = ["name" => $_POST["name_album"]];
         try {
             $response = $fb->post('/me/albums', $data);
             $graphNode = $response->getGraphNode();
             $_POST['album'] = $graphNode['id'];
         } catch (Facebook\Exceptions\FacebookResponseException $e) {
             // When Graph returns an error
             echo 'Graph returned an error: ' . $e->getMessage();
             exit;
         } catch (Facebook\Exceptions\FacebookSDKException $e) {
             // When validation fails or other local issues
             echo 'Facebook SDK returned an error: ' . $e->getMessage();
             exit;
         }
     }
     if ($error == 0) {
         $data = ['message' => "Photo chargé depuis l'application Hakoopix ", 'source' => $fb->fileToUpload($_FILES["fileToUpload"]["tmp_name"])];
         try {
             $response = $fb->post('/' . $_POST['album'] . '/photos', $data);
             header("Location: /participate");
         } catch (Facebook\Exceptions\FacebookResponseException $e) {
             $error_msg = 'Error: ' . $e->getMessage();
         }
     }
     header("Location: /participate");
 }
 public function updateAlbum($albumId)
 {
     $fb = new Facebook\Facebook(['app_id' => '959119600818575', 'app_secret' => '9f0062f110ea6d3589e7debcb04c2268', 'default_graph_version' => 'v2.5']);
     //Récupère token Admin
     $fb->setDefaultAccessToken($_SESSION['token']);
     try {
         $response = $fb->get('/196951203980314?fields=access_token');
         $token = $response->getGraphNode()->asArray();
         $tokenId = $token['access_token'];
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         // After you're done debugging, comment out the below lines
         $result = $e->getMessage();
         echo "<pre>";
         print_r($result);
         echo "</pre>";
     }
     $fb->setDefaultAccessToken($tokenId);
     //Ajout des images
     $data = ['message' => "Logo", 'source' => $fb->fileToUpload($_FILES["update-logo"]["tmp_name"])];
     try {
         $response = $fb->post('/' . $albumId . '/photos', $data);
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         $error_msg = 'Error: ' . $e->getMessage();
     }
     $data = ['message' => "Banner", 'source' => $fb->fileToUpload($_FILES["update-banner"]["tmp_name"])];
     try {
         $response = $fb->post('/' . $albumId . '/photos', $data);
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         $error_msg = 'Error: ' . $e->getMessage();
     }
 }
Пример #8
0
 function postAll($postable_and_user_data)
 {
     // echo $temp['user_obj']['userid_returned'] ." post==".$temp['post_id'];
     foreach ($postable_and_user_data as $temp) {
         $batch_array = [];
         $fb = new \Facebook\Facebook(['app_id' => $temp['config_obj']['appId'], 'app_secret' => $temp['config_obj']['secret'], 'default_graph_version' => $this->default_graph_version]);
         $fb->setDefaultAccessToken($temp['user_obj']['access_token']);
         //use link post
         $data = [];
         if ($temp['post_image_path']) {
             //use photo with message
             // $data = [
             //   'message' => 'My awesome photo upload example.',
             //   'source' => $fb->fileToUpload('/path/to/photo.jpg'),
             // ];
             $data['message'] = $temp['post_obj']['message_blog'];
             $data['source'] = $fb->fileToUpload($temp['post_image_path']);
             $post_type = $end_point = "photos";
         } else {
             // $linkData = [
             //   'link' => 'http://www.example.com',
             //   'message' => 'User provided message',
             //   ];
             $data['message'] = strip_tags($temp['post_obj']['message_blog']);
             $post_type = $end_point = "feed";
             if ($temp['post_obj']['url']) {
                 $data['link'] = $temp['post_obj']['url'];
                 $post_type = "link";
             }
         }
         // get all Postable Pages ['page_id'] = ['name'=>"some thing","access_token"=>"page token"] etc.
         $user_model = $temp['user_obj'];
         $postable_page = $user_model->getFBPages($only_postable_page = true);
         try {
             // Returns a `Facebook\FacebookResponse` object
             if ($user_model['post_on_timeline']) {
                 $response = $fb->post('/me/' . $end_point, $data, $temp['user_obj']['access_token']);
             }
             $page_responses = [];
             // post on all postable pages
             foreach ($postable_page as $page_id => $page_info) {
                 $page_responses[] = $fb->post('/' . $page_id . "/" . $end_point, $data, $page_info['access_token']);
             }
         } catch (Facebook\Exceptions\FacebookResponseException $e) {
             echo 'Graph returned an error: ' . $e->getMessage();
         } catch (Facebook\Exceptions\FacebookSDKException $e) {
             echo 'Facebook SDK returned an error: ' . $e->getMessage();
         }
         if ($user_model['post_on_timeline']) {
             $graphNode = $response->getGraphNode();
             //todo save social posting record into database
             $social_posting = $this->add('xepan\\marketing\\Model_SocialPosters_Base_SocialPosting');
             $social_posting['user_id'] = $temp['user_id'];
             $social_posting['post_id'] = $temp['post_id'];
             $social_posting['campaign_id'] = $temp['campaign_id'];
             $social_posting['post_type'] = $post_type;
             $social_posting['postid_returned'] = $graphNode['id'];
             $social_posting['posted_on'] = $this->app->now;
             $social_posting['status'] = "Posted";
             $social_posting->save();
         }
         foreach ($page_responses as $page_response) {
             $graphNode = $page_response->getGraphNode();
             //todo save social posting record into database
             $social_posting = $this->add('xepan\\marketing\\Model_SocialPosters_Base_SocialPosting');
             $social_posting['user_id'] = $temp['user_id'];
             $social_posting['post_id'] = $temp['post_id'];
             $social_posting['campaign_id'] = $temp['campaign_id'];
             $social_posting['post_type'] = "Page_" . $post_type;
             // for recognization of posting page
             $social_posting['postid_returned'] = $graphNode['id'];
             $social_posting['posted_on'] = $this->app->now;
             $social_posting['status'] = "Posted";
             $social_posting->save();
         }
         //update posting_on in schedule table
         if ($temp['schedule_id']) {
             $schedule = $this->add('xepan\\marketing\\Model_Schedule')->tryLoad($temp['schedule_id']);
             $schedule['posted_on'] = $this->app->now;
             $schedule->save();
         }
     }
 }
Пример #9
0
function FBSDK($mix)
{
    //Facebook SDK Begin
    require_once 'Facebook/autoload.php';
    //include facebook api library
    ######### edit details ##########
    $appId = '1714491162120189';
    //Facebook App ID
    $appSecret = '965e4556c4a984932a55f443bfafab11';
    // Facebook App Secret
    $return_url = 'http://app-zawikawm07.rhcloud.com/connect.php';
    //return url (url to script)
    $homeurl = 'http://zawikawm.com/photomix/index.php';
    //return to home
    $fbPermissions = 'publish_actions,public_profile,email,user_friends, user_photos';
    //Required facebook permissions
    ##################################
    if (isset($_SESSION["zkid"])) {
        $PicLocation = $mix;
        // Picture ID from Index page
    }
    $fb = new Facebook\Facebook(['app_id' => $appId, 'app_secret' => $appSecret, 'default_graph_version' => 'v2.4']);
    //try to get access token
    try {
        $helper = $fb->getRedirectLoginHelper();
        $session = $helper->getAccessToken();
    } catch (FacebookRequestException $ex) {
        die(" Facebook Message: " . $ex->getMessage());
    } catch (Exception $ex) {
        die(" Message: " . $ex->getMessage());
    }
    //get picture ready for upload
    $data = ['message' => '', 'source' => $fb->fileToUpload($PicLocation)];
    //try upload photo to facebook wall
    $graph_node = '';
    if ($session) {
        try {
            $photo_response = $fb->post('/me/photos', $data, $session);
            $graph_node = $photo_response->getGraphNode();
        } catch (FacebookRequestException $ex) {
            die(" Facebook Message: " . $ex->getMessage());
        } catch (Exception $ex) {
            die(" Message: " . $ex->getMessage());
        }
    } else {
        //if login requires redirect user to facebook login page
        $login_url = $helper->getLoginUrl($return_url, array('scope' => $fbPermissions));
        header('Location: ' . $login_url);
        exit;
    }
    if (isset($graph_node["id"]) && is_numeric($graph_node["id"])) {
        //href="http://www.facebook.com/profile.php?preview_cover='.$graph_node["id"].'"
        echo "<script>window.top.location.href='http://www.facebook.com/photo.php?fbid=" . $graph_node["id"] . "&type=1&makeprofile=1&makeuserprofile=1';</script>";
    } else {
        //Nothing
    }
    //Facebook SDK end
}
 function createAlbum()
 {
     $fb = new Facebook\Facebook(['app_id' => '959119600818575', 'app_secret' => '9f0062f110ea6d3589e7debcb04c2268', 'default_graph_version' => 'v2.5']);
     //Récupère token Admin
     $fb->setDefaultAccessToken($_SESSION['token']);
     try {
         $response = $fb->get('/196951203980314?fields=access_token');
         $token = $response->getGraphNode()->asArray();
         $tokenId = $token['access_token'];
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         // After you're done debugging, comment out the below lines
         $result = $e->getMessage();
         echo "<pre>";
         print_r($result);
         echo "</pre>";
     }
     $fb->setDefaultAccessToken($tokenId);
     $target_dir = "images/";
     $target_file = $target_dir . basename($_FILES['banner']['name']);
     $uploadOk = 1;
     $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
     $error = 0;
     $error_msg = "";
     if (isset($_POST["submit"])) {
         $check = getimagesize($_FILES["banner"]["name"]);
         if ($check === false) {
             $error_msg = "File is not an image.";
             $error = 1;
         }
         $check = getimagesize($_FILES["logo"]["name"]);
         if ($check === false) {
             $error_msg = "File is not an image.";
             $error = 1;
         }
     }
     if ($_FILES["banner"]["size"] > 500000) {
         $error_msg = "Sorry, your file is too large.";
         $error = 1;
     }
     if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
         $error_msg = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
         $error = 1;
     }
     //Vérification de l'existance de l'album
     $_POST["title"] = trim($_POST["title"]);
     if (empty($_POST["title"])) {
         $response = $fb->get('/196951203980314/albums?fields=id,can_upload');
         $albums = $response->getGraphEdge()->asArray();
         $albumFacebook = false;
         foreach ($albums as $album) {
             if ($album["id"] == $_POST['album']) {
                 $albumFacebook = true;
                 break;
             }
         }
         if (!$albumFacebook) {
             $error_msg = "L'upload is not allowed in this album.";
             $error = 1;
         }
     } else {
         $data = ["name" => $_POST["title"]];
         $response = $fb->post('/196951203980314/albums', $data);
         $graphNode = $response->getGraphNode();
         $_POST['album'] = $graphNode['id'];
     }
     if ($error == 0) {
         $data = ['message' => "Logo", 'source' => $fb->fileToUpload($_FILES["logo"]["tmp_name"])];
         try {
             $response = $fb->post('/' . $_POST['album'] . '/photos', $data);
         } catch (Facebook\Exceptions\FacebookResponseException $e) {
             $error_msg = 'Error: ' . $e->getMessage();
         }
     }
     if ($error == 0) {
         $data = ['message' => "Banner", 'source' => $fb->fileToUpload($_FILES["banner"]["tmp_name"])];
         try {
             $response = $fb->post('/' . $_POST['album'] . '/photos', $data);
         } catch (Facebook\Exceptions\FacebookResponseException $e) {
             $error_msg = 'Error: ' . $e->getMessage();
         }
     }
 }
Пример #11
0
// 	if($item["name"] == "Profile Pictures"){
// 		$album_id = $item["id"];
//      echo "FOUND PROFILE PICTURES";
// 		break;
// 	}
// }
$data = ['caption' => 'Show your support to our missionaries around the world by using this filter for your Facebook profile pic. Let us encourage them as they share the gospel of Jesus Christ in different places by keeping them in our prayers. #praygivego

  Click on this link to add the filter to your profile picture:
  uecpasaymissionmonth.orgfree.com
  (currently supports only laptops and tablets; if you\'re on a mobile phone, use a browser instead of the Facebook app)

  If the previous link does not work for you, please use this instead: 
  uecpasaymissionmonth.orgfree.com/uploader.php

  For more information about Missions Month, please visit facebook.com/UECPasay', 'source' => $fb->fileToUpload($processedImgPath)];
try {
    // Returns a `Facebook\FacebookResponse` object
    $response = $fb->post('/' . $album_id . '/photos', $data, (string) $accessToken);
    // $response = $fb->post('/me/photos', $data, (string) $accessToken);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    $response = $fb->post('/photos', $data, (string) $accessToken);
    exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    $response = $fb->post('/photos', $data, (string) $accessToken);
    exit;
}
// Delete the processed image once posted to facebook
unlink($processedImgPath);