?
Solved

run curl in vista

Posted on 2011-05-12
11
Medium Priority
?
255 Views
Last Modified: 2012-06-22
Hi,

Just a few questions on curl. I have apache 2.x and php 5.3 on my vista home machine.

1) I'm wondering how I can run this bit of code:
curl -F type=client_cred \
 -F client_id=your_app_id \
 -F client_secret=your_app_secret \
 https://graph.facebook.com/oauth/access_token

Open in new window


2) What are the backslashes at the end of the lines of the command above? Is that a return carriage? So do enter one line at a time in the above?

3) Can someone give me the code in php for the above code? In other words, executing the code above using php's curl_init() and curl_exec().

Much thanks,
Victor
0
Comment
Question by:Victor Kimura
  • 7
  • 4
11 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 35751867
1) You can download and run "curl for windows" http://curl.haxx.se/download.html

2) the backslashes are indicating that the command continues onto the next line

3) coming soon...
0
 
LVL 43

Expert Comment

by:Rob
ID: 35751882
<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token");

// set the form data, assuming client_cred, your_app_id and your_app_secret are all PHP variables
$form_data = Array(
    "type"=>$client_cred,
    "client_id"=>$your_app_id,
    "client_secret"=>$your_app_secret
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $form_data);

curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?> 

Open in new window

0
 

Author Comment

by:Victor Kimura
ID: 35758033
Hi tagit,

That's great. Thank you for the code! I haven't tested it but I will shortly. Just wondering if there is any output from the browser can I capture it by this code:

$output = curl_exec($ch);

$fh = fopen('prn.txt', 'w');
fwrite($fh, $output); 

Open in new window


Victor
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 43

Expert Comment

by:Rob
ID: 35759593
this is probably more applicable if you are wanting to capture the data somehow as this example writes the output to the file you can then read from
<?php

$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

Open in new window

0
 

Author Comment

by:Victor Kimura
ID: 35760814
Hi tagit,

Thanks.

I'm wondering which one should I download for the Windows curl program:
cygwin or generic

I have vista 32-bit. The generic ends up with only a windows 2000/xp version for the 32-bit.

0
 
LVL 43

Expert Comment

by:Rob
ID: 35766448
try using the php code first without downloading curl, you shouldn't need it.
0
 

Author Comment

by:Victor Kimura
ID: 35766538
Hi tagit,

Yeah, I tried the code and tried to save the output to a file. It's blank. So I don't know if facebook gave the wrong code or not. I was going to test it the curl on windows. I didn't include the security code but the result is just a blank output. I didn't receive any errors in the php. Is there perhaps something wrong with my php code?

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token");

$your_app_id = '206755489364466';
$your_app_secret = '';//for security reasons I didn't include this.

// set the form data, assuming client_cred, your_app_id and your_app_secret are all PHP variables
$form_data = Array(
    "type"=>$client_cred,
    "client_id"=>$your_app_id,
    "client_secret"=>$your_app_secret
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $form_data);
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
fclose($fp);
?> 

Open in new window

0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 35766548
I'll have a look and test your code buy in the meantime download the generic first rather than trying to set up cygwin.
Let me know how it goes
0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 2000 total points
ID: 35767343
i've tested this on my local server and it works fine.

I had to change / add a few things:
I've changed the url to google for testing
Added the variable $client_cred
Uncommented the curl extension in the PHP.ini file, which you'll only need to do if you are running your own server (otherwise check that your host supports this OR create a php file with one line <?=phpinfo();?>)
<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
//curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token");
curl_setopt($ch, CURLOPT_URL, "http://www.google.com.au/");

$client_cred = "832179798983";

$your_app_id = '206755489364466';
$your_app_secret = '';//for security reasons I didn't include this.

// set the form data, assuming client_cred, your_app_id and your_app_secret are all PHP variables
$form_data = Array(
    "type"=>$client_cred,
    "client_id"=>$your_app_id,
    "client_secret"=>$your_app_secret
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $form_data);
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
fclose($fp);
?>

Open in new window

0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 2000 total points
ID: 35767348
I've changed the url to google for testing
Added the variable $client_cred
Uncommented the curl extension in the PHP.ini file, which you'll only need to do if you are running your own server (otherwise check that your host supports this OR create a php file with one line <?=phpinfo();?>)
0
 

Author Closing Comment

by:Victor Kimura
ID: 35774652
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Six Sigma Control Plans
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question