how can i do it with cURL for automation

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 .
Mehran GoudarziAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
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.
0
Mehran GoudarziAuthor 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 .
0
Julian HansenCommented:
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

1
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Mehran GoudarziAuthor Commented:
if every time i refresh page it send with another mediaid? How can i sure it send all media_ids?
0
Ray PaseurCommented:
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.
0
Julian HansenCommented:
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?
0
Ray PaseurCommented:
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.
0
Mehran GoudarziAuthor Commented:
im using GET Method and do it with curl -X -d "url" . Thanks .
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mehran GoudarziAuthor Commented:
my solution was best
0
Julian HansenCommented:
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?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Curl

From novice to tech pro — start learning today.