We help IT Professionals succeed at work.

how can i do it with cURL for automation

Mehran Goudarzi
on
68 Views
Last Modified: 2017-04-08
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

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

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 .
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

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
Author of the Year 2014

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.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

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
Author of the Year 2014

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.
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
my solution was best
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

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?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions