i am trying to integrate alchemy api in my project which is in php.
before few days everything was working fine but now the rest api endpoint http://access.alchemyapi.com/ which i called in my program is giving error 404 not found
please if any can tell why it is giving this error.
following is the snippet of code where i have called the rest api
<?php
class AlchemyAPI {
private $_api_key;
private $_ENDPOINTS;
private $_BASE_URL = 'http://access.alchemyapi.com/calls';
*/
public function AlchemyAPI() {
//Load the API Key from api_key.txt
$key = trim(file_get_contents("api_key.txt"));
$this->_api_key = $key;
//Initialize the API Endpoints
$this->_ENDPOINTS['sentiment']['url'] = '/url/URLGetTextSentiment';
$this->_ENDPOINTS['sentiment']['text'] = ' /text/TextGetTextSentiment';
$this->_ENDPOINTS['sentiment']['html'] = '/html/HTMLGetTextSentiment';
/* rest of the code */
?>
I just cloned the PHP SDK from the AlchemyAPI GitHub repo and was able to run the example just fine. Try running the example with: php example.php
You can also try running the tests with: php tests.php. It calls each API endpoint and that should tell you if one of them is causing an issue.
If that doesn't work, if you have modified the alchemyapi.php file, you can try undoing your changes or perhaps re-cloning the repo. I'm not sure if it's just a copy/paste issue, but it looks like there might be a wayward */ in your code snippet.
Related
I am trying to install the CodeIgniter RESTClient and RESTServer libraries for my solution. (philsturgeon-codeigniter-restclient and chriskacerguis-codeigniter-restserver ).
I managed to get the rest server up and running, but I am encountering issues with the rest client.
These are the steps I did to come where I am now:
Copy the Rest.php file (downloaded from GitHub) and put it in the libraries folder
Download the Curl library and put it in libraries
Modified the code in Rest.php to uncomment $this->_ci->load->library('curl'); (if I hover over the usages of the curl library in this file I get the following message):
Field 'curl' not found in CI_Controller
I create a new controller called "Restclient" to test my API. In this controller I created the following method:
function rest_client_example($id)
{
$this->load->library('rest', array(
'server' => 'localhost/codeigniter/api/users/'
));
$user = $this->rest->get('volunteer', array('id' => $id), 'json');
var_dump($user);
}
Browsing to http://localhost/codeigniter/api/restclient/rest_client_example/25 then gives me
D:\wamp\www\codeigniter\application\controllers\api\Restclient.php:36:null
When executing the following code instead of the above, I do get a correct result:
$this->load->library('curl');
$t = $this->curl->simple_get('api/users/volunteer', array('id'=>$id));
var_dump($t);
So I do know that the curl is working.
My guess is that I am doing something wrong with the loading of the curl library?
I know your question is specific to the Libraries mentioned here. Have you tried anything else? I've had really good success with guzzle http
https://github.com/guzzle/guzzle
So i started building something like a wrapper class for the SOAP API of Magento 1.7.0.2 CE following the instructions here
<?php
class magSoap
{
private $client;
private $session;
function __construct()
{
$this->client = new SoapClient('http://localhost:7655/magento1702CE/index.php/api/soap/?wsdl');
var_dump($this->client);
file_put_contents("xml.txt",file_get_contents("http://localhost:7655/magento1702CE/index.php/api/soap/?wsdl"));
$this->session = $this->client->login('test', '1234567890');
echo "hello";
}
function test()
{
var_dump($this->client->call($this->session, 'sales_order.list'));
}
}
?>
when i run the following code
$tester = new magSoap();
$tester->test();
i get the following
googling the error the answer i keep seeing is that i got invalid XML so i navigated to the URL i used in SoapClient and i didn't see anything wrong. then i created that file_put_contents line so i could output the xml to a text file and use this WSDL Analyzer but doesn't show me any errors
the SOAP Login is test, the key is 1234567890, the SOAP Role has full access, i have disabled "Auto-redirect to Base URL", php_soap is enabled in WAMP Server and PHP version is 5.6.25.
Why is it this code still wont work?
I spent many hours in a integration with Magento..
In my case I found out that the SOAP Response of my call had some special html characters and then the SOAP considered is as not an XML response.
What helped me was putting a try-catch in the soap call and use the soap methods __getRequest() and __getResponse() to see what was going on.
Hope it helps someway :)
I want to run custom php code in laravel directly without using any routes or http requests..
I hope I can make it clear, I mean, like those online tools that runs php code by writing php code in browser, and then run it, and view result..
I found this handy project (Run-PHP-Code) to run PHP in browser directly, but I can't use models of my laravel project in PHP code..
How can I include laravel 's environment, so that I can for example:
$tag= new Tag;
where Tag is a model in laravel project, that would result into:
Fatal error: Class 'Tag' not found in D:\xampp\htdocs\widgetsRepository\app\controllers\Run-PHP-Code-master\index.php(49) : eval()'d code on line 3
Any idea? this would be very useful!
EDIT
I tried Brian suggestion at his answer, but I got this error now:
Call to a member function connection() on null
at vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php
public static function resolveConnection($connection = null)
{
return static::$resolver->connection($connection);
}
so, I think I only need to get database sorted, then I can do experiments easily..
I've never tried to run code from a laravel project directly, I just copy and paste parts of the code into Run PHP Code.
That being said, it should be possible to run the code using the method taken from this StackOverflow question:
The Composer autoload script, to autoload all of your classes:
require __DIR__.'/../bootstrap/autoload.php';
And if you need things from the IoC container, you'll:
$app = require_once __DIR__.'/../bootstrap/start.php';
Then you will be able to do things like:
$post = Post::find(1);
I am trying to make the Restful API documentation in PHP swagger, what I did before is that I changed the JSON to work out, now I know we can make the JSON by making PHP files and using swagger notation. I did check the Pet.php example and I get the code but I don't know how to execute the file to get the JSON API documentation which I can link with my Swagger UI. I read the documentation but it is so confusing and I don't know how to get through this problem can anyone help, please? Here is the link I study but to no worth.
https://github.com/zircote/swagger-php
Swagger-PHP for generating JSON file for Swagger-UI
Can anyone tell me step-by-step how to generate the API documentation in JSON? I will be very thankful to him thanks.
There are two way to achieve this in swagger-php 2.0.
I.
The first solution is to create a controller or script which will generate the documentation on each request. This is a good solution in a development environment where you want to see quickly the outcome of your changes.
Here is an example of a controller which does this.
<?php
namespace Controllers;
use Swagger\Annotations as SWG;
use Swagger;
/**
* #SWG\Swagger(
* basePath="/path/to/opration/",
* produces={"application/json"},
* swagger="2.0",
* #SWG\Info(
* version="1.0.0",
* title="My API"
* )
* )
*
*/
class Documentation {
const API_PATH = "path/to/my/documented/files/";
public function show(){
$swagger = Swagger\scan(self::API_PATH);
return json_enconde($swagger); //you can echo this in the calling script.
}
}
Note: The example above assumes you installed Swagger-php with Composer and that the calling script include the composer generated autoload file (usually called: vendor/autoload.php).
II.
The first solution consisting of generating a static json API documentation is described here: https://stackoverflow.com/a/21380432/2853903
This solution recommended for production deployment, where you would not want to regenerate the documentation on every request.
I am trying to use a SOAP Client-Server in my computer and it doesn't look like it is going to work, I am getting this error Error Fetching Http Headers when I try to run my SOAP Client.
I have been looking and the solution that I have encountred is to increase the default_socket_timeout from 60 to 120 seconds and it doesn't work for me, also I have seen another solution that is putting the vhost in my apache KeepAlive Off and that didn't work.
The WSDL is working fine because I try to use it in another computer and it work.
I am running PHP Version 5.3.5-1ubuntu7.4 in Linux Mint using Zend Framework, I hope some of you can help me fix this thank you.
I'm sorry but I don't know what you are using to set up your SOAP service.....
If you can give more information about your SOAP service (poss Zend_Soap given the Zend Framework tag) etc that would be great.
Also, as a quick alternative, you say you've looked at the WSDL on another computer, perhaps try the application in an alternative environment to ensure it's not an environment issue.
May be a simple issue with your client-server code.
UPDATE: Ok so I realised the example I mentioned yesterday wasn't fully implemented so I've hacked something together quickly that you can try to see if it works in your environment.
The code is a mix of something I found here (an example of Zend_Soap_Server) and something from another SO question here (an example of a basic SOAP service test).
I've tested it at my end using ZF 1.11 and the example I'm outlining uses the default Application path you get with a new ZF project (e.g models are in directory application/models so the model shown is headed up Application_Model_Classname).
If it works, you can tweak accordingly....if it doesn't work we can try something else.
Start by creating a new SOAP controller and set the class up like this:
<?php
class SoapController extends Zend_Controller_Action
{
public function init()
{
ini_set("soap.wsdl_cache_enabled", "0"); //disable WSDL caching
$this->_helper->layout()->disableLayout(); //disable the layout
$this->_helper->viewRenderer->setNoRender(); //disable the view
}
public function indexAction ()
{
if (isset($_GET['wsdl'])) {
//return the WSDL
$this->handleWSDL();
} else {
//handle SOAP request
$this->handleSOAP();
}
}
private function handleWSDL ()
{
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setComplexTypeStrategy($strategy);
$autodiscover->setClass('Application_Model_SoapService');
$autodiscover->handle();
}
private function handleSOAP ()
{
$server = new Zend_Soap_Server(null,
array('uri' => "http://YOURDOMAIN/soap?wsdl"));
$server->setClass("Application_Model_SoapService");
$server->handle();
}
public function testAction()
{
$client = new Zend_Soap_Client("http://YOURDOMAIN/soap?wsdl");
try {
echo $client->testMethod('test');
} catch (Exception $e) {
echo $e;
}
}
}
In the class above, the WSDL is automatically generated using Zend_Soap_Autodiscover with a SoapService.php file at application/models/SoapService.php used as the template. Note the DocBock comments above each method in your target class are integral to this process.
Next create the SoapService.php file in the default models folder:
<?php
class Application_Model_SoapService
{
/**
* testMethod
*
* #param string $string
* #return string $testSuccess
*/
public function testMethod(string $string)
{
$testSuccess = 'Test successful, the message was: ' . $string;
return $testSuccess;
}
}
If all is working as it should be you can visit:
http://YOURDOMAIN/soap?wsdl
to see the WSDL and visit:
http://YOURDOMAIN/soap/test
to get a success message with the string you specified in the client request within the testAction() code in the SoapController class as part of the message.
Let me know if it's working or not and we can go from there.
I'll be able to have another look on Monday.