Link to home
Start Free TrialLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

run curl in vista

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
Avatar of Rob
Rob
Flag of Australia image

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...
<?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

Avatar of Victor Kimura

ASKER

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
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

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.

try using the php code first without downloading curl, you shouldn't need it.
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

ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia 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
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
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
Thank you