how can i do it with cURL for automation

Mehran Goudarzi
Mehran Goudarzi used Ask the Experts™
on
i have PHP file and upload it on my localhost . here is my include file on php :

<?php
set_time_limit(0);
date_default_timezone_set('UTC');

require_once '/var/www/html/insta/vendor/autoload.php';

//////////////////////
/////// MEDIA ////////
$mediaId = '1479882119026549924_4483535640';
$commentText = 'Test';
//////////////////////
try {
    $debug = true;
    $ig = new \InstagramAPI\Instagram($debug);
    $ig->setUser($username, $password);
    $ig->login();
   // $ig->enableMediaComments($mediaId);
    $result = $ig->comment($mediaId, $commentText);
    var_dump($result);
} catch (\Exception $e) {
    echo $e->getMessage()."\n";
}

Open in new window


Now i want
$mediaId = '1479882119026549924_4483535640';

Open in new window

 this id change every time ,

for example i have one text File include 100 media_id , now every time cURL send it with different Media_id .
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Where do the media_id's come from?

You need to setup a loop that reads the media id's from where ever they come from and then calls the function that does the cUrl with that media id.

Your code is confusing because you seem to be calling two different functions with $mediaId - one of them is commented out.

Author

Commented:
Where do the media_id's come from?
 it come From text file like mediaid.txt


You need to setup a loop that reads the media id's from where ever they come from and then calls the function that does the cUrl with that media id.
 exactly i don't know how to do this .

i now try another way , i try use GET Method , now my url like this : http://localhost/inst/index.htm?mediaid=12312312123

how can i send GET with cURL i know -X can do it but exactly don't know how .
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Assume media id's are in a file spearated by CR's i.e
123
346
789

Get the media id's from the file
$ids = file('mediaid.txt');
$debug = true;
$ig = new \InstagramAPI\Instagram($debug);
$ig->setUser($username, $password);
$ig->login();
foreach($ids as $id) {
  $result = $ig->comment($id, $commentText);
  var_dump($result);
}

Open in new window

PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Author

Commented:
if every time i refresh page it send with another mediaid? How can i sure it send all media_ids?
Most Valuable Expert 2011
Top Expert 2016

Commented:
Generally it's wise to learn to walk before you try to run.  You need to have a foundation in how scripting languages work.  This can help you get that foundation.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html

When you want to work with a collection of data, you use arrays.
http://php.net/manual/en/book.array.php

To get each individual element from the array, you use an iterator.
http://php.net/manual/en/control-structures.foreach.php

The foreach() iterator will "send all media_ids" one at a time.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
if every time i refresh page it send with another mediaid? How can i sure it send all media_ids?
What does your code look like?
Most Valuable Expert 2011
Top Expert 2016

Commented:
I'm not sure I understand where cURL fits in here.  Julian's example seems more straightforward.  If you have a plain-text file with all the media ids you can read this file with the PHP file() function.  Here's the documentation explaining how file() works.
http://php.net/manual/en/function.file.php

All of the PHP functions are documented in the online man pages, and the manual is translated into a variety of languages.  So any time you see a piece of PHP code that you do not understand, just look up the functions online to see what the author intended.  I have a window open to php.net 100% of the time.  I just can't memorize all of this stuff (PHP has over 1,500 functions) so I refer to the manual.
im using GET Method and do it with curl -X -d "url" . Thanks .

Author

Commented:
my solution was best
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Ok but the answer does not really relate to the question asked - the question (as I understand it) was how to send the request with different Media ID's - was my interpretation wrong?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial