curl LinkedIn API - api

I obtained the oauth token and oauth token secret for the LinkedIn API via Python. I'd like to make some REST calls via curl now and I tried the following ;
curl -v "http://api.linkedin.com/v1/people/~" -d "oauth_token=xxxxxxxxxx" -d "oauth_token_secret=xxxxxxxxxxxxx"
I've used the LinkedIn API in Python but wanted to use in curl. Am I missing something here ?
Any suggestions in this regard will be highly appreciated.
Thank you for your help.

You need to sign the requests using OAuth - usually the best way to do this is to use a library (like you mentioned, the python library works well). You can scoop the HTTP traffic to see what additional headers are being sent. The developer portal at http://developer.linkedin.com has an overview of the OAuth stuff, but it'd be pretty tough to get a working implementation for Curl because each signature you generate will be different (based on timestamp).

Related

How to use Google sheets REST API directly to create a sheet

I have a PHP application which, unfortunately, already uses the 1.1.4 version of the Google Client API, and I am unable to change that, which makes the 2.X version of the Google PHP Sheets API unavailable to me.
However, I'm hoping to be able to use the Google Sheets REST API directly, making my own curl calls (using Guzzle if that's at all interesting).
I'm brand new to the Google API and I've been all over their documentation, but I haven't been able to figure out how to do some basic things.
For the purposes of this question I want to simply create a new Google spreadsheet via the API, from a tool like POSTman.
I get that I first have to obtain an OAuth2 token via https://www.googleapis.com/auth/spreadsheets. The problem is that I can't quite figure out what to pass this call. I'm assuming it requires a GET since POST returns an error saying that method is unavailable.
Once I get that token, how do I use it when I POST to https://sheets.googleapis.com/v4/spreadsheets
Can someone provide a very basic example of the calls I might make directly to simply create a very basic default spreadsheet?
Or am I thinking about this all wrong? All help is appreciated.
If you already have an OAuth2 access token, you can pass it in the "Authorization" header:
curl -L -d '{}' \
-H "Authorization: Bearer <INSERT ACCESS TOKEN HERE>" \
-H 'Content-Type: application/json' \
https://sheets.googleapis.com/v4/spreadsheets
I just verified that curl command creates a new sheet.
Unfortunately as you already indicated, that's probably the simple part, and Getting an OAuth2 access token is more challenging.
Here's a (relatively painful, unfortunately) approach I use sometimes:
You should first create your own project in the API Console or Cloud Platform console, and configure it for your own OAuth2 client id and client secret.
Next, for just playing around, from the Google OAuth2 Developer Playground at https://developers.google.com/oauthplayground/, set your Client Id and Client Secret under the "OAuth 2.0 configuration" (it's the Settings icon - the little gear in the top right). The places to enter those will be hidden until you check "Use your own OAuth credentials". You can then get an access token, with the scopes https://www.googleapis.com/auth/spreadsheets and https://www.googleapis.com/auth/drive, by following the steps on the left.
For more playing around, you could then construct the POST right in step 3, or use the access token from Step 2 in the curl command above.
Best of luck - it's tricky stuff to get the auth parts right. There are lots of moving parts, and I'm just illustrating the high points here.
Tragedy about the library issue -- the PHP Quick Start appears to deal with the auth relatively cleanly.
Tim
Here's the official spreadsheets.create reference. Here's a list of Sheets API Samples. I would suggest that you leave the current version you're using and play with the PHP Quickstarts just so you can have a grasp of how it works.
This is going to be less than satisfying, but after fighting with it a while I looked to see if I could go against the premise of my question: That I couldn't upgrade to the latest Google Sheets PHP API.
As it turns out there was a way. That made all of this a lot easier.
Google's documentation is frustratingly incomplete, but I managed to get it all working anyway. Both of you gave me key pointers. Thanks for your help.

Login Github with Curl

I tried call this command
curl -l -u "my_user_name" https://my-enterprise-github.com
Then, I input my password manually.
But it returns this
<html><body>You are being redirected.</body></html>
Please explain what's wrong with my command.
Thank you.
cURL should not be used for access to GitHub's (or most web) UI without specific reasons. GitHub provides an API to allow accessing data as a well-defined structure.
You mentioned wanting to get-a-single-pull-request. This relies on a URL pattern following GET /repos/:owner/:repo/pulls/:number.
So if you had a GitHub account, facebook, and wanted to look up a specific pull request 15947 in react-native. The full URL would be
https://api.github.com/repos/facebook/react-native/pulls/15947
The cURL command would be
curl -u osowskit -X GET https://api.github.com/repos/facebook/react-native/pulls/15947
Note that:
You will likely want to start using a PAT or OAuth token instead of username/password
There are tools that make exploring the GitHub API easier. postman or octokit
To start with you may want the -L flag. From the cURL Frequently Asked Questions
3.8 How do I tell curl to follow HTTP redirects?
Curl does not follow so-called redirects by default. The Location: header that informs the client about this is only interpreted if you're using the -L/--location option. As in:
curl -L http://redirector.com
Not all redirects are HTTP ones, see 4.14
There's also a CLI now that can be helpful for many similar use-cases:
https://cli.github.com/
$ gh pr list
Showing 2 of 2 open pull requests in Roblox/service-comms-nomad
#16 chi1 Traefik 1.7 GLB jobs chi1-glb-prep
#6 Cgt/t2 cgt/t2

How to make Twitter API call through curl in unix

I would like to pull the data from Twitter REST API. I have created the consumer key, secret and Access token, secret. I have tried with "Test OAuth", it generates a CURL command but if I change any one parameter then it is giving the below error.
Message: {"errors":[{"code":32,"message":"Could not authenticate you."}]}
Now I would like to call the twitter API using CURL in shell script for different screenNames.
I want a sample command some thing like mentioned below
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=2&screen_name=aswin' APIKEY:"xxxxxx",Acesstoken:"yyyyyyyy"
Thanks in advance.
Regards,
Aswin
I found the answer.
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' \
--data 'count=2&screen_name=twitterapi' \
--header 'Authorization: OAuth oauth_consumer_key="AAAAAAAAAAAAAAAAAAAA", oauth_nonce="BBBBBBBBBBBBBBBBBBBBBBB", oauth_signature="CCCCCCCCCCCCCCCCCCCCCCCCCCC", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1471672391", oauth_token="DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", oauth_version="1.0"'
Since your specific query doesn't require a user context you can use Application only authentication to make this request. The bearer token won't change per request so it should allow you to keep using curl.
https://dev.twitter.com/oauth/application-only
n.b. it won't work for all endpoints, but should for the case you listed.
Because most twitter requests require calculating the oauth signature, you should either write a client yourself or reuse an existing command line client.
https://github.com/twitter/twurl
https://github.com/sferik/t
https://github.com/yschimke/oksocial/wiki (Mac focused/cross service)
As you saw any change to the request will generally invalidate the query, and even time is one of the inputs.

Authenticating to Magento Rest API via Curl and token-based authentication fails

As all I want to do is connect to my own site, I should be able to ignore oAuth and do token-baseed authentication as per:
http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html
My curl request looks exactly like:
curl -X POST "https://magento.host/index.php/rest/V1/integration/admin/token" \
-H "Content-Type:application/json" \
-d '{"username":"test#example.com", "password":"123123q"}'
The response I get is a HTML page from my own site that basically says 'page not found' I'm obviously going to the correct domain, but it seems something else in the URL is incorrect. Any ideas?
Am I using the wrong URL?
In version 1.9 you need to create a Guest endpoint. Then you don't need to use oAuth. You can see how to use it here: http://devdocs.magento.com/guides/m1x/api/rest/introduction.html
An authentication system that uses REST so that you do not need to actually track or manage the users in your system. This is done by using the HTTP methods POST, GET, PUT, DELETE. We take these 4 methods and think of them in terms of database interaction as CREATE, READ, UPDATE, DELETE.
There is no direct way to use REST token based authentication on the Magento 1.x version. You need to write this functionality to you for your own. I have write this functionality by using REST API and you can also follow this article for more details.
https://www.ipragmatech.com/magento-token-base-rest-api-for-authentication-and-authorization

Access JIRA API with api key without username and password

Currently I'm accessing JIRA API in C#.Net application with username and password. But I need to access the JIRA API without entering a username and a password even without hashed username and passwords. Is there any way to create an API key and access JIRA API with that?
Yes, JIRA supports OAuth for that purpose, see: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication
Unfortunately there's no C# sample code provided, but you should be able to assemble a solution from the other programming languages here:
https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src
You should use a generic OAuth library anyhow.
Oauth is great for when you need the actual user to log in and you are in the context of a browser.
However, for server-to-server communication that is not linked to any specific user (e.g. CI) you may want to create a "bot" account on your jira server and authenticate with API tokens. Creation of tokens is described here: https://confluence.atlassian.com/cloud/api-tokens-938839638.html
Then you can use [user-email]:[auth-token] as user/password to basic auth. Examples:
Curl
curl -u bot#company.com:AAABBBCCC https://[company].atlassian.net/rest/api/latest/issue/DEV-123
NodeJS got:
const issueContent = await gotService.get(
'https://[company].atlassian.net/rest/api/latest/issue/DEV-123',
{
auth: 'bot#company.com:AAABBBCCC'
}
)
Best approach for this is to read the documentation of the JIRA version you are using, since different versions could have different ways to approach Rest APIs.
For me below endpoint worked with Basic auth:
curl -u username:password -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta