Can anyone please give a Simple Example of UserVoice API call in PHP that retrieve something (could be anything like article etc etc) because i am unable to find any Example that is doing something like that...!!
I have seen at many Places even i searched a lot before using it that is there any example for PHP to retrieve the data using UserVoice API but unable to find so after lots of things i found solution myself here is an example i am posting but few things needed:
Make Sure you have the API Key which you can get by going in Settings>Channels
Apply for the API Client in the API section clicking "Add API client" button fill the form and it will generate a API Key and some other useful information
Now Open your PHP File Lets say you want to get all the articles on your Website using API then you can use following code:
$r = new HttpRequest('https://YOUR_DOMAIN_NAME/api/v1/articles.json', HttpRequest::METH_GET);
$r->addQueryData(array('client' => 'INSERT_YOUR_API_KEY_HERE'));
try {
$r->send();
if ($r->getResponseCode() == 200) {
$obj=json_decode($r->getResponseBody());
print_r($obj);
}
}
catch (HttpException $ex) {
echo $ex;
}
Related
I am connecting PipeDrive with Post Affiliate Pro (with it's API) and am using Zapier webhooks (POST). Therefore I use PHP scripts on my server in which I talk to Post Affiliate Pro. So I have variables in my PHP script which I need to return in order to use them in another webhook/or general action step. In Zapier the only variable I get when testing the step is a String with my response message (and whatever variable I put in there). But I need to get all variables on their own (I guess all in a JSON).
So my question is: How can I return variables in an HTTP POST request to make them available (in the dropdown list?) in Zapier to use them in the next webhook?
At the moment I have something like this:
if ($result->isError()) {
echo 'Error: '.$result->getErrorMessage();
} else {
//echo 'Ok: '.$result->getInfoMessage();
echo json_encode($orderID);
I am using 'echo' but I've also tried to use 'return' which didn't lead to any results. I've also tried to use json_encode to return a JSON but without luck. Or do I even need to use another Zapier step? Or am I not able to return values with a POST webhook at all? Do I need to use a "Catch Hook" webhook? I am completely new to Zapier and PHP.
Image shows just two Strings ('Text' & 'Text Transaktion') available in Zapier but no other variables
Thanks for your help!
I finally found it out by myself. I have to return one JSON, which includes everything. It's also not possible to echo anything at the same time as this would result in the output of just one string with all the values in it (like I had it before).
So something like this does the job:
if (!isset($returnValue)) {
$returnValue = new stdClass();
$returnValue->order_id = $orderID;
$returnValue->result_message = $resultMessage;
}
print_r(json_encode($returnValue));
I want to integrate coinsecure api in my code, Here is the url for api which I have used.
Url : https://github.com/coinsecure/plugins/tree/master/master/php/SwaggerClient-php
Where there are two method to install/integrate API :
Using composer.
Manual process.
So I have select second one manual Process so based on document information
Download all file and add into my third part library folder.
And add require_ones autoload.php file.
Up to this step it'll fine but problem is now occur when I have perform action using this coin secure.
Suppose I want to get lowest rate over the last 24 hours so for that one bellow code is provided by api.
Code :
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$api_instance = new Swagger\Client\Api\ExchangeTradeDataApi();
$accept = "accept_example"; // string | JSON, XML or CSV can be returned (Optional)
try {
$result = $api_instance->v1exchangemin24Hr($accept);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ExchangeTradeDataApi->v1exchangemin24Hr: ', $e->getMessage(), PHP_EOL;
}
?>
And when I run this code it'll give me error as below :
[404] Error connecting to the API
(https://api.coinsecure.in/v1/exchange/max24Hr)
Can any one have idea why it give me error..?
Strange, there's an extra / in your URL before the v1 causing a 404 error. Instead it should be https://api.coinsecure.in/v1/exchange/max24Hr
Looks like their PHP library is hard coded wrong.
From their github library line 76
if ($apiClient == null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('https://api.coinsecure.in/');
}
Then they include the / again on line 136
$resourcePath = "/v1/exchange/ask/low";
Notice how the base url ends with a / and the path starts with a /. You can change it yourself and it should work, but I bet the other calls in the library are messed up too. Maybe let them know so they can correct the library.
Location: plugins/master/php/SwaggerClient-php/lib/Api/ExchangeTradeDataApi.php
I once was a Web-Designer who knew HTML/CSS. Now I'm a 3D animator, but I want to get back into the Web-Developer world.
But there's so much new to learn. E.g. flat file cms. Wow!
But my question for now is how I read an API, create the right PHP file to pull an XML file and put that data onto a web page.
Specificially I'm interested in this mobile.de API:
http://services.mobile.de/manual/search-api.html
And it seems that this is the XML that I need:
http://services.mobile.de/schema/ad-1.0.xsd
What are the next steps to get this beginner's project going?
I guess I need some sort of PHP file that uses GET and some sort of authentication. How can I test, if and what will come back?
And how do I use the pulled information to put in into a new page?
Or is my thinking all wrong?
Many thanks in advance.
Ben
Little bit you can understand through this post and answers on this post:
How to echo xml file in php
If you don't mind using already created library, please check : PHP Curl Class
Taken from the readme:
PHP Curl Class is an object-oriented wrapper of the PHP cURL extension that makes it easy to send HTTP requests and integrate with web APIs.
And this code snippet (also taken from the readme) could be your starting point:
$curl = new Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('');
$curl->setReferrer('');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get('http://www.example.com/');
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
}
else {
echo $curl->response;
}
var_dump($curl->requestHeaders);
var_dump($curl->responseHeaders);
Oh, and it's an unlicensed license type software.
I'm trying to integrate my facebook app with PHP. What I need to do is have users go to the app-page, authenticate the app and then somehow I want to end up with a variable that contains the info I need so I can store it in MySQL.
I downloaded the facebook SDK, but I cannot figure out how to make it work. All the examples I can find refer to a file called facebook.php - but there is no such file in the SDK (maybe the changed it?).
I managed to get it working with JavaScript, but I don't know how to get from JavaScript to php (the user object, that is).
I would prefer to just run it entirely through php. What I'm trying to do is very simple, but I don't understand what I'm doing wrong. The following, for instance, does not work:
<?php
FacebookSession::setDefaultApplication('appid', 'appsecret');
require facebook-php-sdk-v4-master\src\Facebook\FacebookCanvasLoginHelper.php;
$helper = new FacebookCanvasLoginHelper();
try {
$session = $helper->getSession();
} catch(FacebookRequestException $ex) {
echo "error";
} catch(\Exception $ex) {
echo "error 2";
}
if ($session) {
echo "logged in";
}
?>
Gives PHP Fatal error: Class 'FacebookSession' not found in
Where do I go? I don't think the Facebook getting started guide is helpful at all. It just starts out with "you have to do this" (what I did above) - but that doesn't work?
Looks like they changed the whole SDK for PHP 5.4.
Well there's a few options, you could go with the older SDK and all those tutorials you found will work for that. Or you could learn some new things!
I suggest that if you want to use the new Facebook SDK, you go ahead an learn about composer first, it makes including libraries a piece of cake and all you'd have to do is include the autoloader at the top of the file. Once done, you can just follow the example and it should work.
If you don't want to learn composer, you'll have to include all the required files manually. Here's a basic example.
In your example it looks like the error was because you were calling
FacebookSession::setDefaultApplication
Before you'd actually included the SDK
I need some help in retrieving the event id from the event_new PHP API method. I can see that the URL method works well by returning an XML file containing the new ID, however the response I get from the PHP API method is simply 'NULL'.
The documentation says that both the XML and URL methods return the new event ID, can anyone offer some assistance on what I need to do?
Cheers
Paul
I'm not able to reproduce your error. Do you have any sample code to share?
What PHP version are you running?
This test works fine for me:
//PHP API Client Lib is available here: https://github.com/ryanjarvinen/eventbrite.php
include "Eventbrite.php";
//Authorization tokens are outlined here:
// http://developer.eventbrite.com/doc/authorization/
$eb = new Eventbrite(array('app_key'=>'YOUR_APPLICATION_KEY','user_key'=>'YOUR_USER_KEY'));
try{
//Docs on how to use the API's event_new method are located here:
// http://developer.eventbrite.com/doc/events/event_new/
$response = $eb->event_new(array('title'=>'test event_new','start_date'=>'2012-12-12 12:00:00','end_date'=>'2012-12-12 12:12:12'));
print "The new event_id is: {$response->process->id}";
}catch( Exception $e){
var_dump($e);
}
There are a few more PHP-specific usage notes available on github.
Most of the general information about authentication tokens, as well as specifics on input and output parameters per API method, should be available on http://developer.eventbrite.com/