I've been all over the web and its pretty unclear to me how to get the yelp api to work using the php code sample provided.
So far I have
Grabbed the sample php file from here https://raw.githubusercontent.com/Yelp/yelp-api/master/v2/php/sample.php
I have not modified this file at all except to add my authentication.
Gotten all of my tokens,keys and secrets
$CONSUMER_KEY = "GOT IT!";
$CONSUMER_SECRET = "GOT IT!";
$TOKEN = "GOT IT!";
$TOKEN_SECRET = "GOT IT!";
I am including the OAuth, which I got from here http://oauth.googlecode.com/svn/code/php/
require_once('OAuth.php');
In the read me document it states to simply go to the php file and check out the results
When I visit the page on my site, I get this error message(I removed my actual consumer key)
0 businesses found, querying business info for the top result ""
Result for business ""
found: {"error": {"text": "Signature was invalid", "id": "INVALID_SIGNATURE", "description": "Invalid signature. Expected signature base string: GET\u0026http%3A%2F%2Fapi.yelp.com%2Fv2%2Fbusiness%2F\u0026oauth_consumer_key%KEY%26oauth_nonce%3Db7869743b1599850a2db6e92fc2a6239%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1414090806%26oauth_token%3DyJMyLRsFiAIuKSuclV1d6pb0pwjwiEat%26oauth_version%3D1.0"}}
I just signed up for the api keys today and have checked and double checked and they are correct in the php file.
I've also attempted to add parameters to the url to see if I can get any results and its always the same error.
My end goal is to pull in all reviews for a business by using its phone number as a search parameter. If anyone can provide an example of how I would pass the parameter that would be so helpful too.
After getting and placing the token and secret from the app you created on Yelp. You have to edit one more thing in Sample.php on 13th last line (or line:138) you will see the following:
`$longopts = array(
"term:: /* Place Term here e.g. 'Bars' */ ",
"location:: /* Place Location here e.g. 'San Francisco, CA' */ ",
);`
Or the location can be change from your Yelp Developer ID by editing the location.
Hope you got the answer.
To get yelp business details using phone number:
You can try a http or curl request to
http://api.yelp.com/phone_search?phone=8009773609&ywsid=sQ3g4WLACeGWOFXXXXXXXX
ywsid = Yelp CONSUMER_KEY
Related
I am using this solution to select an individual post from a user's feed.
I am using PHP Facebook SDK on the latest version 5.7.
Previously this had worked with no problem, I made my request like:
$response = $this->fb->get(
'/'.$user['id']. '_' .$post_id.'/?fields=id,description,name,full_picture',
$this->get_access_token()
);
And I would get all the fields. However, over the last few months, this has stopped working.
The access_token requests the following permissions:
['user_events', 'user_posts']
I can't find any documentation on the solution outlined in the Stack Overflow post. So I am not sure if I need any more permissions.
I do not get an error when sending this request, I just get the ID back and nothing else. This can be confirmed in the Graph API Explorer:
The v5.0 docs show that when requesting a post I can get full_picture, name and description without mentioning any additional permissions required.
However that same page recommends making the request with just the post ID:
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{post-id}',
'{access-token}'
);
}
Which does not work, you
{
"error": {
"message": "(#12) singular statuses API is deprecated for versions v2.4 and higher",
"type": "OAuthException",
"code": 12,
"fbtrace_id": "ACs2rpwobcW8zSFyL_0Q2yQ"
}
}
The error does mention statuses and not posts but I am not sure how to distinguish the difference between those, I figured they were the same.
Has anyone else stumbled across this and found a solution?
It turns out that the fact it was called status was important. I made a request to the users feed, and noticed that some older posts were returning the data that I needed. I had a look through the list of fields and appended message and type to get the following response:
Not very well documented I guess. But got there in the end, hopefully this can help someone else in future.
Alright so I am having some troubles understanding how to use the open weather API.
I have tried using it as
<?php
$request = file_get_contents('http://api.openweathermap.org/data/2.5/forecast/city?id=myidblablabla'); //example ID
$jsonPHP = json_decode($request);
echo $jsonPHP->city;
?>
But I get an error saying
Catchable fatal error: Object of class stdClass could not be converted
to string in
Now there is 1 more question that I have to ask, how do I get certains City Temperature, humidity etc? From the code I received I get only Moscow
To simplify it, you can also transform the json into array instead.
$jsonPHP = json_decode($request,true);
Now let's discuss it briefly. According to the documentation (http://openweathermap.org/current),
Note also that I've never used this API before. I'm just trying to help here.
If you hit api.openweathermap.org/data/2.5/weather?lat=35&lon=139
It responds as
{"coord":{"lon":139,"lat":35},
"sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
"weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
"main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
"wind":{"speed":7.31,"deg":187.002},
"rain":{"3h":0},
"clouds":{"all":92},
"dt":1369824698,
"id":1851632,
"name":"Shuzenji",
"cod":200}
Now assuming you want to take the weather and humidity , it just :
weather :
echo $jsonPHP["weather"][0]["id"];
humidity:
echo $jsonPHP["main"]["humidity"];
Note also that, If you hit http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139 and get the responds as
{"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}
For the case, they've explained here :
http://openweathermap.org/faq#error401 which is :
Q: API calls return an error 401
A: Starting from 9 October 2015 our
API requires a valid APPID for access. Note that this does not mean
that our API is subscription-only now - please take a minute to
register a free account to receive a key.
We are sorry for inconvenience but this is a necessary measure that
will help us deliver our services to you faster and more reliably.
For FOSS developers: we welcome free and open source software and are
willing to help you. If you want to use OWM data in your free software
application please register an API key and file a ticket describing
your application and API key registered. OWM will review your request
lift access limits for your key if used in open source application.
In API 1.0, we can use users/profile_image/:screen_name
For example : http://api.twitter.com/1/users/profile_image/EA_FIFA_FRANCE
But, it doesn't work anymore in API 1.1.
Do you have a solution, please ?
You can also get the twitter profile image by calling this kind of url :
https://twitter.com/[screen_name]/profile_image?size=original
For instance : https://twitter.com/VancityReynolds/profile_image?size=original
Got the info from this post :
https://twittercommunity.com/t/how-to-get-user-image-original-size-with-api-1-1/10187/14
The user's profile image
Okay, so you want a user's profile image. You're going to need to take a look at the twitter REST API 1.1 docs. This is a list of all the different requests you can make to their API (don't worry, I'll get to how you actually do this later on).
There are multiple ways to get the user's profile image, but the most notable one is: users/show. According to the docs for this, the users/show method:
Returns a variety of information about the user specified by the required user_id or screen_name parameter. The author's most recent Tweet will be returned inline when possible.
Well, the user profile image must be in there somewhere, correct?
Let's have a look at a typical response to a request for this information, using the users/show url (we'll use my profile as an example).
I've cut off some from the bottom, because there is a lot of data to go through. Most importantly, you'll see what you require:
This is the profile_image_url key that you need to get access to.
So, how do you do all this? It's pretty simple, actually.
Authenticated Requests
As you rightly pointed out, as of June 11th 2013 you can't make unauthenticated requests, or any to the 1.0 API any more, because it has been retired. So OAuth is the way to make requests to the 1.1 API.
I wrote a stack overflow post with an aim to help all you guys make authenticated requests to the 1.1 API with little to no effort.
When you use it, you'll get back the response you see above. Follow the posts instructions, step-by-step, and you can get the library here (you only need to include one file in your project).
Basically, the previous post explains that you need to do the following:
Create a twitter developer account
Get yourself a set of unique keys from twitter (4 keys in total).
Set your application to have read/write access
Include TwitterApiExchange.php (the library)
Put your keys in a $settings array
Choose your URL and request method (Post/Get) from the docs (I put the link above!)
Make the request, that's it!
A practical example
I'm going to assume you followed the step-by-step instructions in the above post (containing pretty colour pictures). Here's the code you would use to get what you want.
// Require the library file, obviously
require_once('TwitterAPIExchange.php');
// Set up your settings with the keys you get from the dev site
$settings = array(
'oauth_access_token' => "YOUR_ACCESS_TOKEN",
'oauth_access_token_secret' => "YOUR_ACCESS_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
);
// Chooose the url you want from the docs, this is the users/show
$url = 'https://api.twitter.com/1.1/users/show.json';
// The request method, according to the docs, is GET, not POST
$requestMethod = 'GET';
// Set up your get string, we're using my screen name here
$getfield = '?screen_name=j7mbo';
// Create the object
$twitter = new TwitterAPIExchange($settings);
// Make the request and get the response into the $json variable
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
// It's json, so decode it into an array
$result = json_decode($json);
// Access the profile_image_url element in the array
echo $result->profile_image_url;
That's pretty much it! Very simple. There's also users/lookup which effectively does the same thing, but you can:
Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters.
If you ever need to get more than one user's details, use that, but as you only require one user's details, use users/show as above.
I hope that cleared things up a bit!
You say you want to use Twitter API 1.1 and yet you don't want to authenticate your requests.
Unauthenticated requests are not supported in API v1.1. So please adjust to the API change. See updates :
https://dev.twitter.com/blog/planning-for-api-v1-retirement
https://dev.twitter.com/docs/rate-limiting/1.1
You can get image from profile_image_url field of https://api.twitter.com/1.1/users/show.json request. Either a id or screen_name is required for this method. For example :
GET https://api.twitter.com/1.1/users/show.json?screen_name=rsarver
See details here https://dev.twitter.com/docs/api/1.1/get/users/show
I try the above methods to get the profile URL but it does not work for me. I think because Twitter changes API v1.1 to API v2.0.
I found a simple method to get a profile URL.
I use Twitter API v2 there User Lookup -> User by Username API part
Code Sample:
https://api.twitter.com/2/users/by/username/{user_name}?user.fields=profile_image_url
For Example:
https://api.twitter.com/2/users/by/username/TwitterDev?user.fields=profile_image_url
Of course, You should request with your Bearer Token then it properly work. For that, I recommend a platform it calls postman. It really helps for calling API.
Above example code return JSON like this:
{
"data": {
"name": "Twitter Dev",
"profile_image_url": "https://pbs.twimg.com/profile_images/1445764922474827784/W2zEPN7U_normal.jpg",
"username": "TwitterDev",
"id": "2244994945"
}
}
Additional:
If You want the Profile Image to be a higher size. Then you can put size in place of normal in the URL. For More Details read this one
Like This:
https://pbs.twimg.com/profile_images/1445764922474827784/W2zEPN7U_400x400.jpg
Give a vote to help more developers. 🍵
As the previous answers and comments point out:
Twitter API v1.0 is deprecated
Twitter API v1.1 requires OAuth
OP (#Steffi) doesn't want to authenticate
Pick any two; with all three it's a no-go. #Jimbo's answer is correct (and the proper way to do it), but excludes #3. Throwing out #1 means going back in time. But, we can throw out #2, and go directly to the source:
curl -s https://twitter.com/EA_FIFA_FRANCE |
sed -ne 's/^.*ProfileAvatar-image.*\(https:[^"]*\).*$/\1/p'
The sed command just says, find the line that contains "ProfileAvatar-image" and print the substring that looks like a quoted URL.
This is less stable than an authenticated API call, since Twitter may change their HTML at any time, but it's easier than dealing with OAuth, and no official rate limits!
The PHP translation should be straightforward.
try this
http://api.twitter.com/1/users/profile_image/{twitter_account}.xml?size=bigger
In API 1.1 the only way is to connect your application, retrieve the user by
https://dev.twitter.com/docs/api/1.1/get/users/show
and retrieve after his picture
profile_image_url
Hare is a very simple way to get Twitter Profile picture.
http://res.cloudinary.com/demo/image/twitter_name/w_300/{User_Name}.jpg
it's my Profile picutre:
Big: http://res.cloudinary.com/demo/image/twitter_name/w_300/avto_key.jpg
Small: http://res.cloudinary.com/demo/image/twitter_name/w_100/avto_key.jpg
you can regulate size by this part of URL - w_100, w_200, w_500 and etc.
I have downloaded a PHP SDK for the UPS API. I have the following code and have no idea what an end point URL is. The documentation does not provide any information on what this is.
//Configuration
$access = "0C81234564C2567";
$userid = "leannetest";
$passwd = "456hththd8hf";
$accessSchemaFile = "schemas/AccessRequest.xsd";
$requestSchemaFile = "schemas/RateRequest.xsd";
$responseSchemaFile = "schemas/RateResponse.xsd";
$endpointurl = 'add URL here';
$outputFileName = "XOLTResult.xml";
Can anyone help?
Endpoint url explaination in the UPS document. it consists of four parts which are explained below.
For example if we are going to use "Rate" service than our urls should be as below.
Testing and integration URL : https://wwwcie.ups.com/ups.app/xml/Rate
Production URL : https://onlinetools.ups.com/ups.app/xml/Rate
As per the documentation if we devide the url in four parts all of them are as listed below.
Protocol : https
Name of server : wwwcie.ups.com (testing) OR onlinetools.ups.com (production)
Path of service : ups.app/xml/Rate
name of the service : Rate OR Ship OR QVEvents
I just replied to explain UPS endpoint url in detail so it might help
An API endpoint "defines the address or connection point to a Web service. It is typically represented by a simple HTTP URL string". So basically, the endpoint URL is the URL of the web service that are you attempting to interact with.
SOURCE:
http://en.wikipedia.org/wiki/Web_Services_Description_Language#Objects_in_WSDL_1.1_.2F_WSDL_2.0
EDIT: It appears from the documentation that the Rate webservices endpoint URL is https://wwwcie.ups.com/webservices/Rate.
SOURCE:
UPS. (January 2, 2002). Rating Package Web Services Developers Guide. Section 1.9.3 Server Availability Check. Accessed in Rating API found on this page: https://www.ups.com/upsdeveloperkit/downloadresource?loc=en_US
The shipping endpoint url is:
https://wwwcie.ups.com/webservices/Ship
In case anyone needs it, since it's not documented in their developers kit.
Indeed the documentation is poor but with a little google trick I got the list of all the endpoint URLs
Type in google search:
site:https://onlinetools.ups.com/ups.app/xml/
In this way, it will show you all the endpoints.
Note: Do not use the sandbox URLs because they don't work at all :(
Anyway, here is the list:
https://onlinetools.ups.com/ups.app/xml/TimeInTransit
https://onlinetools.ups.com/ups.app/xml/License
https://onlinetools.ups.com/ups.app/xml/QVEvents
https://onlinetools.ups.com/ups.app/xml/Register
https://onlinetools.ups.com/ups.app/xml/AV
https://onlinetools.ups.com/ups.app/xml/ShipAccept
https://onlinetools.ups.com/ups.app/xml/Void
https://onlinetools.ups.com/ups.app/xml/XAV
https://onlinetools.ups.com/ups.app/xml/Track
https://onlinetools.ups.com/ups.app/xml/Rate
https://onlinetools.ups.com/ups.app/xml/ShipConfirm
https://onlinetools.ups.com/ups.app/xml/LabelRecovery
I hope this help
I've spent the last three hours trying to get a simple Twitter status update to work using Zend_Service_Twitter and Zend_Oauth_Token_Access. Infuriatingly, I keep getting the following response:
object(Zend_Rest_Client_Result)#34 (2) {
["_sxml:protected"]=>
object(SimpleXMLElement)#39 (2) {
["request"]=>
string(33) "/1/account/verify_credentials.xml"
["error"]=>
string(20) "Invalid / used nonce"
}
["_errstr:protected"]=>
NULL
}
Here is the code I have tried:
$token = new Zend_Oauth_Token_Access();
$token->setToken('my token');
$token->setTokenSecret('my token secret');
$params = array('accessToken' => $token,
'consumerKey' => 'my key',
'consumerSecret' => 'my secret'
);
$twitter = new Zend_Service_Twitter($params);
$response = $twitter->statusUpdate('simpletest');
What on Earth is a 'nonce'? If I mess up the token/token secret the error message in the response changes accordingly. However, with correct credentials I keep getting the above noncence (pun intended). Also, I have tried several alternatives such as the ones in this previous post on SO.
Any help would be appreciated!
Update:
In case it helps, or makes things easier, all I am trying to do is update the status of a single Twitter account, which is the application's twitter account. As I commented below #David Caunt's answer, whenever an 'item' gets posted to our site, the site's Twitter status will update to a brief description of the item as well as a link. That's all! This used to work, before oAuth became compulsory to make API calls (all that was needed was to instantiate a Zend_Service_Twitter and pass in our credentials).
Consulting the reference manual, I believe your error is in creating the Zend_Service_Twitter object.
$twitter = new Zend_Service_Twitter(array(
'username' => 'johndoe',
'accessToken' => $token
));
$response = $twitter->status->update('My Great Tweet');
You do not need to pass in the key and secret again, as they are contained in the access token used to sign the request.
See also my comment above explaining the nonce.
UPDATE:
I've tried the code in a minimal environment and you're right, it simply doesn't work.
You can see all of my code in a GitHub gist. It's deliberately minimal, avoiding MVC and other complications.
You may take comfort in the fact that a Zend_Http_Client returned from the Access Token does work.
Twitter servers were reporting a problem with my nonces, when the error
was in the signature.
My OAuth code was working for most
requests, but when trying to post new
statuses I was getting "Invalid / used
nonce" as a response.
After much debugging, I found out I
was failing to encode spaces as %20
and instead was sending them as +.
After using the correct encoding, it
worked flawlessly.
Twitter servers should have reported a
problem with the signature, not the
nonce.
I don't really expect you guys to
waste any time fixing this (but it
would be nice)... I just want to leave
this note here so next time someone
comes googling for "invalid / used
nonce" they know they have to look at
their encodings too.
From http://code.google.com/p/twitter-api/issues/detail?id=1059
(other solution in comments)