Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ademking authored Jun 2, 2018
1 parent 22bdf16 commit 4ab5254
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"mgp25/instagram-php": "^3.1"
}
}
19 changes: 19 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/*
___ _ _ _ _
| . | _| | ___ ._ _ _ | |__ ___ _ _ | |__<_>
| |/ . |/ ._>| ' ' || / // . \| | || / /| |
|_|_|\___|\___.|_|_|_||_\_\\___/`___||_\_\|_|
By @AdemKouki
GitHub : https://github.com/Ademking/InstaPoster
Email : [email protected]
Facebook : https://github.com/Ademking/InstaPoster
*/
$username = 'INSTAGRAM_USERNAME';
$password = 'INSTAGRAM_PASSWORD';

$image_description = 'Your Description Here ...';
$img_url = 'https://picsum.photos/700/?random';
$photoFilename = "img/rand.jpg";
Binary file added img/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/rand.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
set_time_limit(0);
date_default_timezone_set('UTC');
require __DIR__.'/vendor/autoload.php';


//////////////////////
//////////////////////
/////// CONFIG ///////

require 'config.php';

$debug = true;
$truncatedDebug = true;

//////////////////////
//////////////////////
//////////////////////






function download_img_from_url($imgurl , $photopath) {

$fileName = "$photopath";
$fileUrl = "$img_url";
$ch = curl_init($fileUrl); // set the url to open and download
$fp = fopen($fileName, 'wb'); // open the local file pointer to save downloaded image
curl_setopt($ch, CURLOPT_FILE, $fp); // tell curl to save to the file pointer
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // tell curl to follow redirects
curl_exec($ch); // fetch the image and save it with curl
curl_close($ch); // close curl
fclose($fp); // close the local file pointer

}

download_img_from_url($img_url, $photoFilename);


$ig = new \InstagramAPI\Instagram($debug, $truncatedDebug);
try {
$ig->login($username, $password);
} catch (\Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."\n";
exit(0);
}
try {




$metadata = ['caption' => "$image_description"];
$ig->timeline->uploadPhoto($photoFilename, $metadata);
echo "Upload Done!" ;





} catch (\Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."\n";
}
?>

0 comments on commit 4ab5254

Please sign in to comment.