views:

38

answers:

2

hi guys, i'm doing api calls from php backend like this:

$term     = "AT&T Park";        
$q        = '"'. urlencode($term) .'"';
$url      = "http://search.twitter.com/search.json?q={$q}&rpp=100";
$api_call = file_get_contents($url);

it's not returning anything, but same api call working just fine on my terminal.

here is a little screencast showing what's going on:

http://screencast.com/t/RnZsrwfGcc2q

any ideas?

A: 

You can use cURL in your PHP file. This may work.

http://us3.php.net/manual/en/function.curl-init.php

Rocket
just tried - doesn't work...
Devrim
Sorry about that, it was worth a shot. =(
Rocket
:) thanks anyway!
Devrim
+1  A: 

you need to urlencode the quotes too.

change your code to the following

$term     = '"AT&T Park"';
$q        = urlencode($term);
$url      = "http://search.twitter.com/search.json?q={$q}&rpp=100";
$api_call = file_get_contents($url);

and it should work

Gabriel Sosa
Agree, you should urlencode the double-quotes as well.
kovshenin
this doesn't work properly, it encodes quotes well, but ampersand is funny so i did `$term = '%22'.urlencode("AT` then it worked. I'm going to mark this as an answer, hope it will help others.
Devrim