1

I have a simple iPhone application I am making that will upload pictures to Facebook. To do this, I have to put multiple files on the server. From that, it will go to Facebook. I have my PHP code below that will do that server-side.

The problem is, when I put a variable in the array, it won't work. I have tried all the different options and it's not working out for me.

Any help is appreciated! Thanks.

$args = array(
'message' => 'Photo from the ******** iPhone Application.',
'$short_url' => '$short_url'
);

$url = 'https://graph.facebook.com/'.$album_id.'/photos?access_token='.$get_facebook_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
//returns the photo id
print_r(json_decode($data,true));
4
  • Okay, all the quotations look fine here, what do you get as a result, and what were you expecting? Commented Feb 12, 2011 at 2:20
  • 3
    What is this? '$short_url' => '@$short_url' | Try 'short_url' => $short_url in its place. Single quotes '', do not interpolate. Commented Feb 12, 2011 at 2:21
  • You're right. The @ threw me off track there. Commented Feb 12, 2011 at 2:24
  • Thanks for all the comments! Here's what I had to do: - I removed the '' and facebook didn't reconize it. - I figured it had to do something with the mysql code so I did it a little different and it worked. Now they go to a database, and I run a cron job with it every minute to do it. I think it's a better method because if it fails, It can run again. Commented Feb 12, 2011 at 21:59

3 Answers 3

2

You are using single quotes were you probably should be using a variable directly or double quotes so the variable gets interpolated:

$args = array(
    ...,
   "short_url" => "@$short_url",
);

Or something like that. Depends on the supposed form field names. And "@$var" probaby leads to a file upload with curl.

Sign up to request clarification or add additional context in comments.

Comments

1

Remove the ''s around the variable so it won't be treated as a string.

$args = array(
 'message' => 'Photo from the ******** iPhone Application.',
 'short_url' => $short_url
);

1 Comment

do you think it is what he needs?
0

You probably need

"short_url" => $short_url

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.