I don't want to use libraries for this, I just want to send REST request to the API. Here is API reference for uploading videos. I don't see anywhere in the documentation where to put a video file. Should it be in the header or request body? Does anyone know how this HTTP request should look like?
Here is the official documentation of the Resumable Upload Protocol, which is used by all of Google's public (open source) libraries.
I personally would not recommend you to implement resumable video uploading using bare HTTP request methods. That's quite tricky to done it right. But, if you don't want to use Google's libraries, you have to absorb this doc and implement its specifications the way you need it.
There's also the possibility to upload videos on one go (thus not using the above mentioned protocol). That would entail calling a POST method on the URL:
https://www.googleapis.com/upload/youtube/v3/videos?uploadType=multipart&part=snippet,status,
where you'll have to compose a multipart/related content-type as exemplified below:
POST /upload/youtube/v3/videos?uploadType=multipart&part=snippet,status HTTP/1.1
Host: www.googleapis.com
Content-length: 453
Content-type: multipart/related; boundary="===============8268018375852491166=="
Authorization: Bearer [YOUR_VALID_ACCESS_TOKEN]
--===============8268018375852491166==
Content-Type: application/json
MIME-Version: 1.0
{
"snippet": {
"title": "test video",
"description": "just some test video",
"categoryId": "22"
},
"status": {
"privacyStatus": "private",
"embeddable": false,
"license": "youtube"
}
}
--===============8268018375852491166==
Content-Type: video/mp4
MIME-Version: 1.0
Content-Transfer-Encoding: binary
TEST
--===============8268018375852491166==--
You could use as spring of inspiration for your own code this Python3 script I implemented a while ago. The script takes as input an JSON object specifying the metadata of the video to be uploaded and the video file itself and generates the multipart/related file and the associated Content-Type HTTP header that could well be used by an immendiate curl command. (Issue my script with --help for brief helping info.)
Note that my script is based on Google's own open source code, specifically on discovery.py. This latter script is part of Google's APIs Client Library for Python.
Related
YouTube videos have different resolution default thumbnails to use. We use the "default" version (ie: http://img.youtube.com/vi/UNIQUECODE/default.jpg) to preview youtube videos before showing them.
The problem is that Google PageSpeed then dings the page as having a non-compressed image. (ie: Compressing http://img.youtube.com/vi/UNIQUECODE/default.jpg could save 1.1KiB (23% reduction). ).
Is there anyway to call their API and get a compressed image to show?
There are only the default options offered, they don't have a processing option. One possiblity is a 3rd-party compression service like TinyPNG. Their developer API lets you remotely compress an image:
Features: "You can either upload images directly or specify a URL to the image you want to compress."
A POST request using JSON will compress the Youtube image on TinyPNG's server:
POST /shrink HTTP/1.1
Host: api.tinify.com
Authorization: Basic YXBpOmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1
Content-Type: application/json
{
"source": {
"url": " http://img.youtube.com/vi/UNIQUECODE/default.jpg)"
}
}
The (JSON) response would give you a new compressed image link to use instead of the one from Youtube.
I am making a POST call to get oAuth token in JMeter. So that I can upload files to Google Drive. Below is my request details in JMeter.
POST https://accounts.google.com/o/oauth2/token
POST data:
client_id=<my_client_id>&auth_uri=https%3A%2F%2Faccounts.google.com%2Fo%2Foauth2%2Fauth&token_uri=https%3A%2F%2Faccounts.google.com%2Fo%2Foauth2%2Ftoken&client_secret=<my_client_secret>&grant_type=authorization_code&redirect_uris=%5B%22urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob%22%2C+%22127.0.0.1%3A3000%22%5D%0A&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive
[no cookies]
Request Headers:
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 424
Host: accounts.google.com
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_121)
But I am getting below error. Any help is appreciated. Thanks.
{
:
"error"
: : "invalid_request",
: "error_description" : "Missing required parameter: code"
}
I can not help you with JMeter but I can tell you what the error message means.
The grant_type=authorization_code is the second step in the Oauth2 flow. It has a few required parameters one of them is code.
https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code
The code in question is the code that was returned from the initial request for the user to approve the applications access.
I would also like to add that Google has a number of official client libraries that will deal with these calls for you. Using one of those is much easer then trying to understand the Oauth2 flow if you don't need to. If you cant use the library and you are interested in seeing the full Oauth2 flow to google I have a tutorial on it Google 3 legged Oauth2 flow it shows the pure HTTP calls.
I would recommend using Google OAuth Java Client Library from JSR223 Test Elements using Groovy as a programming language, this is the fastest and the easiest way to obtain/refresh OAuth tokens.
See How to Run Performance Tests on OAuth Secured Apps with JMeter article for detailed explanation and an authorization example.
I have an iOS app that is working and able to connect to a RESTful PHP Webservice. The webservice was initially built in native PHP and now I am migrating it to a Symfony2 web service. On the iOS side, I am sending requests as JSON, the server processes the data and returns a JSON response data, everything works pretty well.
Now, my symfony2 webservice is able to respond with the correct response to requests made from the browser window or terminal using httpie (for testing) and it returns json data in the browswer window if I specify .json in the parameters. However, I am not sure how to make the iOS app send the request rather than the browser. I am using the FOSRestBundle if that information is of any significance. Here is an example from the terminal:
http http://serveripaddress/web/app_dev.php/users/1.json Accept:application/json
It returns json data representation of the user with the id = 1 as expected:
HTTP/1.1 200 OK
Allow: GET, PUT, DELETE
Cache-Control: no-cache
Content-Type: application/json
Date: Fri, 29 Nov 2013 20:15:43 GMT
Server: Apache/2.2.22 (Ubuntu)
Set-Cookie: PHPSESSID=n8o72oq61isruuov1bqgc9udf5; path=/
Transfer-Encoding: chunked
X-Debug-Token: 6c3818
X-Powered-By: PHP/5.3.10-1ubuntu3.8
{
"id": 1,
"last_name": "Robinson",
"first_name": "Jack",
....More data truncated ...
}
From my browser, I can get the same result by using: http://serveripaddress/web/app_dev.php/users/1.json in the address bar. How can I make the iOS app send the same request? I guess the only change I need is in the symfony2 code to accept the request? Kindly give a brief example and I can figure out the rest from the example.
Edited with more detail:
Just to clarify, what I need is how to initiate a connection to the server-side REST Symfony2 application. Again, this I have previously done when using native PHP but how do I connect to a Symfony2 route? While using the native version, what I did was to construct a dictionaryWithObjectandKeys passing key value pairs of the command (on the PHP side) and the arguments as JSON and having the server side return JSON data response and a success or failure, simple and straightforward. How can this be done if I am using Symfony2 which I guess the commands now become a route? I am using AFNetworking and everything on the iOS client side should not need changes except the part where I connect to Symfony2. Kindly give an example to give me a concrete picture.
You can use AFNetworking 2 for example. It is a complete framework that allows you to consume web services (and more).
By the way, you could simply use (and fire) NSURLRequest, but if your application interact a lot with a webService i recommend to use AFNetworking. (Trust me, it is really something that you want to know how to use if you want to make apps on iOS)
I think binding to session and cookies may violate REST nature. I strongly recommend you to use something like WSSE. You can use EscapeWSSEAuthenticationBundle for WSSE. Or create your own.
Also useful link to dive deep:
How to create a custom Authentication Provider
Configure WSSE on Symfony2 with FOSRestBundle
Hi I am trying to setup an api to allow a 3rd parties webhooks a destination to post application/x-www-form-urlencoded.
I have only ever worked with json and xml with the webapi.
Do I need to create a custom mediatype to accept this or should it work by default?
Any suggestions would be appreciated.
UPDATE
I took a look at the example provided however I am still not to sure an example of the data the webhook will send to my api looks like.
How am I meant to setup my controller to accept this?
POST /some-path HTTP/1.1
Host: your.host.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 2837
Connection: keep-alive
Accept: /
environment=prod&domain_prefix=example&type=product.update&payload=%7B%22id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22retailer_id%22%3A%229a5521c3-2d20-11e2-8057-080027706aa2%22%2C%22sku%22%3A%229416050901074%22%2C%22handle%22%3A%221000001%22%2C%22source%22%3A%22USER%22%2C%22active%22%3A%221%22%2C%22name%22%3A%22Ginger+Beer%22%2C%22description%22%3A%22%3Cp%3EA+delicious+ginger+beer+that+is+both+refreshing+and+good+value+for+money.%3C%5C%2Fp%3E%22%2C%22supplier%22%3A%7B%22id%22%3A%229fc84329-2d20-11e2-8057-080027706aa2%22%2C%22retailer_id%22%3A%229a5521c3-2d20-11e2-8057-080027706aa2%22%2C%22name%22%3A%22Brewer+Supplies+Ltd.%22%2C%22description%22%3A%22We+supply+all+things+brewed%5Cn%22%2C%22source%22%3A%22USER%22%7D%2C%22brand%22%3A%7B%22id%22%3A%229fb8e69d-2d20-11e2-8057-080027706aa2%22%2C%22name%22%3A%22Vaughan%27s+Ginger+Beer+Brewing+Company%22%7D%2C%22inventory%22%3A%5B%7B%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22outlet_id%22%3A%229aee412b-2d20-11e2-8057-080027706aa2%22%2C%22attributed_cost%22%3A%221%22%2C%22count%22%3A%2222%22%2C%22reorder_point%22%3A%2212%22%2C%22restock_level%22%3A%2240%22%7D%2C%7B%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22outlet_id%22%3A%229ae97219-2d20-11e2-8057-080027706aa2%22%2C%22attributed_cost%22%3A%221%22%2C%22count%22%3A%2214%22%2C%22reorder_point%22%3A%226%22%2C%22restock_level%22%3A%2220%22%7D%5D%2C%22price_book_entries%22%3A%5B%7B%22id%22%3A%22a1098b59-2d20-11e2-8057-080027706aa2%22%2C%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22price%22%3A%222.00%22%2C%22tax%22%3A%220.25%22%2C%22type%22%3A%22BASE%22%2C%22customer_group_id%22%3A%229b097e69-2d20-11e2-8057-080027706aa2%22%2C%22customer_group_name%22%3A%22All+Customers%22%2C%22tax_id%22%3A%229a025ff0-2d20-11e2-8057-080027706aa2%22%2C%22tax_name%22%3A%22NZ+GST%22%2C%22tax_rate%22%3A%220.150000%22%7D%2C%7B%22id%22%3A%22a1318cf0-2d20-11e2-8057-080027706aa2%22%2C%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22price%22%3A%221.90%22%2C%22tax%22%3A%220.24%22%2C%22type%22%3A%22GENERAL%22%2C%22customer_group_id%22%3A%229b097e69-2d20-11e2-8057-080027706aa2%22%2C%22customer_group_name%22%3A%22All+Customers%22%2C%22tax_id%22%3A%229a025ff0-2d20-11e2-8057-080027706aa2%22%2C%22tax_name%22%3A%22NZ+GST%22%2C%22tax_rate%22%3A%220.150000%22%7D%2C%7B%22id%22%3A%22a13a6320-2d20-11e2-8057-080027706aa2%22%2C%22product_id%22%3A%229fe945bc-2d20-11e2-8057-080027706aa2%22%2C%22min_units%22%3A%2210.00%22%2C%22price%22%3A%221.50%22%2C%22tax%22%3A%220.19%22%2C%22type%22%3A%22BASE%22%2C%22customer_group_id%22%3A%229b097e69-2d20-11e2-8057-080027706aa2%22%2C%22customer_group_name%22%3A%22All+Customers%22%2C%22tax_id%22%3A%229a025ff0-2d20-11e2-8057-080027706aa2%22%2C%22tax_name%22%3A%22NZ+GST%22%2C%22tax_rate%22%3A%220.150000%22%7D%5D%7D
Yes, it supports it out of the box.
Please, take a look on that sample: ASP.NET Web API: Sending Form-Url-Encoded Data
I'm just beginning the implementation of my Web Service for passbook.
In the docs I see there's an optional endpoint for logs, but don't understand what uses/consumes this endpoint?
As far as I can tell, it's only used by humans who wish to check the logs.
For clarity, Apple's docs say the logs should be accessible via a
POST request to webServiceURL /version /log
but I can't see why we couldn't use a GET request to webServiceURL/version/myAppsLogs
According to the specification, Passbook will POST a JSON document to your logging endpoint. GET wouldn't allow submitting data. This JSON document will only have one key "logs" which is an array of strings. You need to respond only with an HTTP 200 status.
A sample communication would look like this:
POST /yourwebServiceURL/v1/log HTTP/1.1
Host: yourserver
Content-Type: application/json
Content-Length: 83
{
"logs" : [
"log message 1",
"log message 2",
"log message n"
]
}
HTTP/1.1 200 OK
Connection: Close
Passbook itself uses this url if it finds an error in the pass, or in your implementation of the api. I definitely recommend logging everything that comes through this url, the errors are pretty comprehensive, and it helped me find some problems I didn't know that I had.
You need to implement the
POST request to webServiceURL /version /log
so Passbook can upload logs to your server.
The GET call to fetch the logs depends on what you do when you receive the logs in the POST call. For example if you save them on a file, you can let the user (probably an admin user) download the file or a part of it.
If you save the each POST action on a row on a database, you can send the last n rows...