Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use Yelp's API in ZF2?
    primarykey
    data
    text
    <p>I'm trying to connect to Yelp's API, currently using ZF2 and ZendOAuth. I don't know why I'm getting a 404. Here is the raw request and response headers.</p> <pre><code>POST /v2/search?term=tacos&amp;location=sf HTTP/1.1 Host: api.yelp.com Connection: close Accept-Encoding: gzip, deflate User-Agent: Zend\Http\Client Content-Type: application/x-www-form-urlencoded Authorization: OAuth realm="",oauth_consumer_key="&lt;key&gt;",oauth_nonce="&lt;nonce&gt;",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1387401249",oauth_version="1.0",oauth_token="&lt;token&gt;",oauth_signature="&lt;signature&gt;" HTTP/1.1 404 Not Found Date: Wed, 18 Dec 2013 21:14:09 GMT Server: Apache X-Node: web41, api_com Content-Length: 8308 Vary: User-Agent Connection: close Content-Type: text/html; charset=UTF-8 X-Mode: rw X-Proxied: lb1 </code></pre> <p>Does that request look like it should connect somewhere? </p> <p>Here's some code. </p> <pre><code> $accessToken = new \ZendOAuth\Token\Access(); $accessToken-&gt;setToken('&lt;token&gt;'); $accessToken-&gt;setTokenSecret('&lt;secret&gt;'); $host = 'http://' . $_SERVER['HTTP_HOST']; $config = array( 'consumerKey'=&gt;'&lt;key&gt;', 'consumerSecret'=&gt;'&lt;secret&gt;', ); $client = $accessToken-&gt;getHttpClient($config); $client-&gt;setUri('http://api.yelp.com/v2/search?term=tacos&amp;location=sf'); $client-&gt;setMethod('POST'); $adapter = new \Zend\Http\Client\Adapter\Socket(); $client-&gt;setAdapter($adapter); $response = $client-&gt;send(); $result = $response-&gt;getBody(); </code></pre> <p>All the examples of OAuth I've seen get the access token with a request token, but Yelp already gave me the token and secret, so I'm trying to construct it manually. </p> <hr> <p><strong>Update:</strong> Changing</p> <pre><code> $client-&gt;setMethod('POST'); </code></pre> <p>to </p> <pre><code> $client-&gt;setMethod('GET'); </code></pre> <p>is the first step, but the parameters can't be added manually to the URL, they have to be added with <code>setParameterGet();</code>. So here's my updated working code. </p> <pre><code>$accessToken = new \ZendOAuth\Token\Access(); $accessToken-&gt;setToken('&lt;token&gt;'); $accessToken-&gt;setTokenSecret('&lt;secret&gt;'); $host = 'http://' . $_SERVER['HTTP_HOST']; $config = array( 'consumerKey'=&gt;'&lt;key&gt;', 'consumerSecret'=&gt;'&lt;secret&gt;', ); $client = $accessToken-&gt;getHttpClient($config); $client-&gt;setUri('http://api.yelp.com/v2/search'); $client-&gt;setMethod('GET'); $params = array('term'=&gt;'tacos', 'location'=&gt;'sf'); $client-&gt;setParameterGet($params); $adapter = new \Zend\Http\Client\Adapter\Socket(); $client-&gt;setAdapter($adapter); $response = $client-&gt;send(); $result = $response-&gt;getBody(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload