Link to home
Start Free TrialLog in
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 .
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

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.
Avatar of Mehran Goudarzi
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
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if every time i refresh page it send with another mediaid? How can i sure it send all media_ids?
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.
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?
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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my solution was best
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?