This is making me crazy. I've been trying out all sorts of things but I just can't figure this out. LinkedIn's documentation is horrible...
All I need to do is simple: I need to search for a company (using a keyword) and retrieve the company id. I have issues with setting up the OAuth request and with making the request. Any advice on how to do this, especially without installing any PHP libraries?
FYI, my code: I got the OAuth.php from here.
require_once 'OAuth.php';
$base_url = 'http://api.linkedin.com/v1/company-search';
$consumer = new OAuthConsumer('mykey', 'mysecret');
$token = new OAuthToken('tokenkey', 'tokensecret');
$parameters = array (keyword => 'Apple');
$request = OAuthRequest::from_consumer_and_token($consumer, $token, "GET", $base_url, $parameters);
print_r($request);
Thanks
You're using a good OAuth library that I do recommend, but it seems to me you're missing on the Linkedin Library, or at least you haven't included the full code.
In any case, try using the simple-linkedinphp library, which uses your oauth library above. I had to use a few libraries in the past, and this is one of the best, particuarly if you're going to use Faceted search. Make sure you also check the quick start guide, it will help you a lot, as well as the class reference. The company search API function could be found here.
You could always use the raw() function for any custom calls not supported by the above function. I had to use that for some calls.
Related
I'm using composer to install the slim-skeleton. Those built in routes work as expected. I understand how to add in my previous routes and database connections, but I've been struggling on how to add in any JWT library. I've searched and searched but I'm not finding much documentation for Slim-4 and what I've tried always seems to fail one way or another.
So for example I use composer to install tuupola/slim-jwt-auth and it says to add the following code:
$app = new Slim\App;
$app->add(new Tuupola\Middleware\JwtAuthentication([
"secret" => "supersecretkeyyoushouldnotcommittogithub"
]));
but where or how exactly do I add it to the middleware? Does it need to be added to app/middleware.php? All the documentation I read has a completely different file structure with other directories and whatnot. Once this is placed in the correct spot it looks like when a request is made without a token I should get a 401 Unauthorized response.
After that part is working I know I need to create a route to get my access token, but I'm not seeing anything about that in this library so I would assume I need another library to encode my token and return it from my request.
Once I actually get a token response and pass it in the headers for my actual request route I would assume I do something like the following
$app->get("/protected-route-name", function ($request, $response, $arguments) {
$token = $request->getAttribute("token");
// Not sure what to put next to verify the token and allow the response or display a error if there is no token or the token in invalid.
});
I'm open to firebase or any JWT library if someone has one they like and that works well, I just need some direction as I feel all the documentation is lacking.
use \Firebase\JWT\JWT;
get token
$headers = apache_request_headers();
if(isset($headers['Authorization'])){
$decoded = JWT::decode($headers['Authorization'], $publicKey, array("RS256"));
.... verify token.
}
$jwt = JWT::encode($payload, $privateKey, "RS256");
boom done.
you don't even really need to use middle ware to do this.
slim made itself way overly complex with that.
But the truth is between slim3 and slim 4, on a very basic setup, the only thing that has changed is the getBody() on the json writing.
honestly, not really sure how useful this is anymore to be honest. everything is cloudbased now. Only reason I found this is trying to figure out how to use Google Identity Platform with Slim.
I'm working on an application that sends SMS to the customers we got.
I'm currently looking the doc (https://docs.ovh.com/fr/sms/envoyer_des_sms_avec_lapi_ovh_en_php/) => it's in french.
They're using a PHP Wrapper, but I really don't know how I can integrate the API to my Laravel Project.
Does someone know how it's working ?
First of all, install the package
composer require ovh/php-ovh-sms
Then, on the controller, you can use the API easily as stated in the documentation.
use \Ovh\Sms\SmsApi;
// Informations about your application
// You may set them to 'NULL' if you are using
// a configuraton file
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumerKey = "your_consumer_key";
$endpoint = 'ovh-eu';
// Init SmsApi object
$Sms = new SmsApi( $applicationKey, $applicationSecret, $endpoint, $consumerKey );
// Get available SMS accounts
$accounts = $Sms->getAccounts();
dd($accounts);
There is a Laravel notification channel specifically for this provider, this will make the whole process much easier, it will allow you to use Laravel's built in notifications functionality without having to write provider specific code.
http://laravel-notification-channels.com/ovh-sms/
I played around with the PHP 7.2 runtime and HTTP trigger on Alibaba Cloud Function Compute. The basic example in the documentation is the following:
<? php
use RingCentral\Psr7\Response;
function handler($request, $context): Response{
/*
$body = $request->getBody()->getContents();
$queries = $request->getQueryParams();
$method = $request->getMethod();
$headers = $request->getHeaders();
$path = $request->getAttribute("path");
$requestURI = $request->getAttribute("requestURI");
$clientIP = $request->getAttribute("clientIP");
*/
return new Response(
200,
array(
"custom_header1" => "v1"
),
"hello world"
);
}
This works quite well. It's easy to get the query parameters from an URL. But the body content is only available in a whole string with
$request->getBody()->getContents();
Although the documentation says that the $request parameter follows the PSR-7 HTTP Message standard, it is not possible to use $request->getParsedBody() to deliver the values submitted by POST method. It didn't work as expected - the result remains empty.
The reason is the underlying technology. Alibaba Cloud Function Compute makes use of the event-driven React PHP library to handle the requests (you can check this by analyzing the $request object). So the $_POST array is empty and there is no "easy way to get POST data".
Luckily, Alibaba's Function Compute handler provides the body content by $request->getBody()->getContents(); as a string like
"bar=lala&foo=bar"
So a solution seems easiser than thought at the beginning, you can e.g. use PHP's own parse_str() function:
$data = [];
$body = $request->getBody()->getContents();
parse_str($body,$data);
If you place this snippet in the handler function, the POST variables are stored in the $data array and ready for further processing.
Hope that this helps somebody who asked the same questions than I. :-)
Kind regards,
Ralf
As you can see in the documentation you need to add a RequestBodyParserMiddleware as middleware to get a parsed PSR-7 request. It seems you didn't do that.
Also keep in mind that only the Content-Types: application/x-www-form-urlencoded and multipart/form-data are supported here. So make sure the client need to send these headers so the request can be parsed. If it's another Content-Type you need to use another middleware.
See: https://github.com/reactphp/http#requestbodyparsermiddleware for more information.
I hope this helps!
#legionth: I apologize that I didn't use the comment feature here, but my answer is too long. :-)
Thanks a lot for your comments - the usage of RequestBodyParserMiddleware is a great solution if you can control the server code. But in the context of Alibaba Cloud Function Compute service this seems not possible. I tried to find out more information about the invocation process - here are my results:
Function Compute makes use of the Docker image defined in https://github.com/aliyun/fc-docker/blob/master/php7.2/run/Dockerfile .
In the build process they download a PHP runtime environment from https://my-fc-testt.oss-cn-shanghai.aliyuncs.com/php7.2.tgz . (I didn't find this on GitHub, but the code is public downloadable.)
A shell script start_server.sh starts a PHP-CGI binary and runs a PHP script server.php.
In server.php a React\Http\Server is started by:
$server = new Server(function (ServerRequestInterface $request) {
[...]
});
[...]
$socket = new \React\Socket\Server(sprintf('0.0.0.0:%s', $port), $loop);
$server->listen($socket);
$loop->run();
As seen in the Function Compute documentation (& example of FC console), I can only use two functions:
/*
if you open the initializer feature, please implement the initializer function, as below:
*/
function initializer($context) {
}
and the handler function you can find in my first post.
Maybe Alibaba will extend the PHP runtime in future to make it possible to use a custom middleware, but currently I didn't find a way to do this.
Thanks again & kind regards,
Ralf
im using a email client that i build to update jira tasks. i have managed to change the assignee and the summary through it. but i cannot seems to find a way to update the status. following is the code i used.
$resolution->id="4";
$update->transitions= array($resolution);
$queryIssue = new Jira($config);
$queryIssue->updateTransition($query,$update);
the class:
public function updateTransition($issueKey,$json){
$this->request->openConnect('https://'.$this->host.'/rest/api/latest/issue/REC-143/transitions?', 'POST', $json);
$this->request->execute();
}
this gives me an error saying
Missing 'transition' identifier
what am i doing wrong here.please let me know.
the way i input the json was incorrect.it should be,
$resolution->transition->id ="4";
$queryIssue->updateTransition('11205',$resolution);
like this. and by the way i used this library to do all my needs with jira. the things which are not included here, i had to implement by my self. which is easy if you know the api urls.take a look at the rest api documentation for the suitable apis you may require.
Can anyone post simple step by step integration for openid into a site which has a login system already?
I decided to use PHP OpenID 2.1.3 but could get where to start and what to do.
I think your best bet is using the OpenID module from the Zend Framework. It can be used on it's own, without having to use the whole framework, and they have a fairly simple explanation on how to use it on their manual pages. It's as simple (if you understand the concept of OpenID) as:
login_page.php:
// Load the library Zend Framework way, or load it yourself...
// Always good to pick apart the library anyway, to see how it works:
Zend_Loader::loadClass('Zend_OpenId');
$consumer = new Zend_OpenId_Consumer();
if(!$consumer->login($_POST['openid_identifier'], 'redirect_to.php'))
{
die('OpenID login failed.');
}
redirect_to.php:
Zend_Loader::loadClass('Zend_OpenId');
$consumer = new Zend_OpenId_Consumer();
if($consumer->verify($_GET, $id))
{
echo htmlspecialchars($id).' is a valid ID.';
}
else
{
// redirect to "login.php?login=failed".
if(!headers_sent())
{
header('HTTP/1.1 307 Temporary Redirect', true, 307);
header('Location: login.php?login=failed');
}
else die('Invalid ID.');
}
It is a lot easier to use than the PHP OpenID Library (php-openid) provided by the OpenID Foundation.
EDIT: How to implement Zend_OpenId (in response to comment).
Download the latest Zend Framework, and extract the folder ZendFramework-1.9.2/library/Zend/OpenId.
There are however a few things you have to do:
Change the class extends value in [...]/OpenId/Exception.php from Zend_Exception to Exception.
Go through every file (tedious, I know) and replace all the require's and include's to absolute path names.
Now you can reference the classes by:
require_once '/path/to/OpenId/Consumer.php';
$consumer = new Zend_OpenId_Consumer();
// If you plan on making your own OpenID's, use 'Provider' instead of 'Comsumer'.
require_once '/path/to/OpenId/Provider.php';
$provider = new Zend_OpenId_Provider();
Now, the best advice I can give you though is to read through the manuals! Don't expect it to work first time... Zend's implementation may be easier, but that doesn't stop OpenID being a pain in the ass!
No, there is no simple guide. There are too many login systems and different implementations to make this simple and straightforward.
For particular scripts, try googling it. For any other scripts, you will have to integrate OpenID into your application. If you use MVC, you're in luck: Have a look at the user model and plug OpenID into it.