|PHP OAuth API||>||All threads||>||Need help with accessing the...||>||(Un) Subscribe thread alerts|
Russell Ramey - 2013-07-31 21:55:11
Today, I just noticed you added a surveymonkey file to gain OAuth access. Thank you so much. I have been playing with it today and got it to return my list of survey_ids. However, I'm looking to target the particular survey responses similar to what is documented at https://developer.surveymonkey.com/io-docs.
What can we do to get the API call to exist as a standalone statement so we can reference the 5 methods: (1) Get Survey List, (2) Get Collector List, (3) Get Response Counts, (4) Get Responses, and (5) Get Survey Details.
I played with changing the targeted surveymonkey endpoint urls - https://api.surveymonkey.net/v2/surveys/get_survey_list but encountered being unable to retrieve all of the data.
Do you have classes available with these methods? I'd love to discuss with anyone working on this.
Manuel Lemos - 2013-07-31 23:23:14 - In reply to message 1 from Russell Ramey
SurveyMonkey API is tricky. Even using their API console it does not work because in some cases they use the API key instead of the client secret. That is totally against the OAuth standards. No wonder people has been having a hard time trying to make this work.
Anyway, all it is possible to do can be done with using the CallAPI function.
Can you show the code you used to call the API endpoints and it did not work, so I can try to reproduce it?
When you say it did not retrieve all the survey data, could that be because you have more than 10 surveys in that account?
Russell Ramey - 2013-08-01 02:55:42 - In reply to message 2 from Manuel Lemos
I have about 8 or 9 surveys. The problem is more with my syntax as I'm not supplying the proper params. My understanding of PHP is more Intermediate than Advanced but can pick up things quickly once their explained to me. I hear ya on Surveymonkey's oAuth process. This is my first time encountering oAuth. I used the console and was successful at getting some responses for all of them but it was difficult to see the survey response details as well. I'm hoping this isn't too complicated. You were able to return an array that you printed out the mapped items using print_r.
I'm referring to the documentation at the developer site - https://developer.surveymonkey.com/mashery/get_survey_details
I basically was trying to replace the following block of code
$parameters = new stdClass;
$success = $client->CallAPI('https://api.surveymonkey.net/v2/surveys/get_survey_list?api_key='.$client->api_key, 'POST', $parameters, array('FailOnAccessError'=>true, RequestContentType'=>'application/json'), $surveys);
with a different url for one of the other endpoints. Any way to make it Authenticate once and then make different calls to the different Url endpoints?
/* i.e. Get Survey Details */
which requires the survey_id as a parameter. How would I specify that parameter? I do get the error below:
[status] => 3
[errmsg] => Required field 'survey_id' is missing
Where do I specify 'survey_id' in that CallAPI function?
Also, I noticed that the callback forces me to login each time I visit that page - prompting me for the username and password. -
Authorize webdesignmx05 to use your SurveyMonkey account.
Is it possible to provide a Authorization Token and API key that allows for open access. I'm looking to automate survey extraction data via a Cron job. Can the login be bypassed since we already have the credentials.
Manuel Lemos - 2013-08-01 05:06:28 - In reply to message 3 from Russell Ramey
SurveyMonkey tokens do not expire, so once you obtained the authorization you do not need to authorize again.
By default the class stores access tokens in sessions. If you are running the script from the command line, sessions do not exist, so authorization tokens are lost.
To have authorization tokens saved for offline access (when the user is not present) you need to copy the value of the access_token variable to somewhere and set the class variable again when you need to call the API later.
You need also to save the value of the variable access_token_type, although for SurveyMonkey for now it is always 'bearer'.
You can also have it saved to a database using a subclass that stores anything you.
There are subclasses for storing tokens in MySQL databases. Take a look at this article to adapt the examples for use with SurveyMonkey.
As for call parameters, SurveyMonkey takes objects encoded as JSON with the parameters defined as properties of those objects.
When you pass the the RequestContentType parameter as application/json, the CallAPI function takes the $parameters parameter and encodes it as JSON to pass it to the SurveyMonkey API.
So if you want to set the survey_id parameter you need to assign a object variable with that name.
$parameters->survey_id = 'some survey id here';
Rohit Sharma - 2014-03-24 10:10:10 - In reply to message 4 from Manuel Lemos
I am also not able to pass the parameter to the api methods of survey monkey.
Could you please give the exact code as an example of $client->CallAPI() method.
Manuel Lemos - 2014-03-24 10:28:59 - In reply to message 5 from Rohit Sharma
As you may see in the example code, SurveyMonkey takes an object in the JSON format, so just set the parameter values as variables of the $parameters object, so the class encodes the parameters properly for you.
$parameters = new stdClass;
$success = $client->CallAPI(
'POST', $parameters, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $surveys);