Avatar of Mehran Goudarzi
Mehran Goudarzi
 asked on

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 .
* Curl* AutomationPHP

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

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.
Mehran Goudarzi

ASKER
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 .
SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mehran Goudarzi

ASKER
if every time i refresh page it send with another mediaid? How can i sure it send all media_ids?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ray Paseur

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.
Julian Hansen

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?
Ray Paseur

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Mehran Goudarzi

ASKER
my solution was best
Julian Hansen

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?