Querying Big Query Table using javascript POST method - javascript

Hi I am new to google biqquery , so i want to make a POST method request to query big query table i am not aware where to pass the Query in the request so please help.

There are several ways to issue a query, but the short version is:
Get an OAuth access token (generally by using the gapi client).
Insert a query job.
Monitor for completion (a job may take a while to run, so you generally need to poll its status with a jobs.get operation).
Retrieve the results from the temporary table.
Inserting a query job can be done through this endpoint:
POST https://www.googleapis.com/bigquery/v2/projects/projectId/queries
The various REST endpoints are described in the public documentation here:
https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#http-request
While you didn't describe your reason for doing this, I'll mention that consuming BigQuery directly is probably not something you want to do from a multi-user website (because each user would need to be a member of your project). You may be better off issuing queries and caching the results on the backend and providing your own frontend to render the results.

Related

Why does Instagram API return two different user_id values for the same user?

Nutshell: PHP implementation gets correct user_id, React.js implementation gets incorrect user_id. Why!?
I implemented the Instagram Basic Display API OAuth flow in PHP and in Javascript under React.
The flow under PHP works fine - I get a code, I POST it using curl to /oauth/access_token, I receive a client_id and an access_token, all fine, subsequent Graph API requests work just fine.
Then I moved to rebuild it in Javascript. Here, when I get a code, and I POST it using fetch to /oauth/access_token, with the same client_id and client_secret, and the same authenticating user, essentially the same request, just a different redirect URL (obviously), I receive a token and a different user_id, one that does not work (it gets a 400 error from Graph API).
Oddly enough, the bad user_id is consistently smaller by 1 than the one that I get with PHP: the good one ends with 93, the bad one ends with 92. If I do the unspeakable and just manually increase the wrong user_id I received, I obtain a valid user_id for which the token works!
So why is Instagram sending me a wrong user_id, and how can I help it?
I finally found the cause, moments ago, after writing the question and earlier wasting 5 hours on analyzing whatever I could think of.
The user_id is sent as a number larger than Number.MAX_SAFE_INTEGER, and thus JSON.parse fails to parse it correctly. Instagram should be encoding the user_id field as a string. This API endpoint thus needs to be parsed manually. I "fixed" mine by filtering the results as such:
text = text.replace(/"user_id":\s*(\d+)/,'"user_id":"$1"'). Still, encoding such large numbers as "numbers" in JSON is a horrible practice and Instagram should fix their API instead.

Passing reference to XBMC json-rpc to identify answer later

I am using XBMC json-rpc with websockets. When I send json request like "method":"Playlist.OnClear" I get response {"id":1,"jsonrpc":"2.0","result":"OK"}.
So if I'll send multiple requests I will get multiple responses and I won't be able to identify which response refers to which request. Is it possible to pass some additional data to request so that it would be added to response (like context in jquery ajax call)?
I don't know is it related to XBMC or json-rpc in general.
Perhaps this question was not answered because it is slightly inaccurate.
Firstly there is no method "Playlist.OnClear, rather Playlist.OnClear is only a non-solicited notification from the media player, on that states the playlist was cleared.
Now the playlist might clear directly as a result of another request you had made, for example Playlist.Clear comes to mind, which is indeed a method.
So when you send the valid json packet
{"jsonrpc":"2.0","method":"Playlist.Clear","params":{"playlistid":0},"id":10101}
You can use the "id" key to add a, guess what, an id to the request, and that very same id will be returned from the mediaplayer
{"id":10101,"jsonrpc":"2.0","result":"OK"}
Furthermore, it is possible to write paired web based requests/response code, but that's not even necessary considering the above...

Javascript (client-side): Database query and Data handling

I have built a web application that accepts a Member_ID # from the client (javascript). The Member_ID is stored as a var in my javascript… now I need to make queries with it…first query to get member information (name) and then join tables to gather information for health plans that the member is elligible under … and so on.
As far as I can remember the concept is… send a async request to the server and wait for a response, once the response is received, store it and then parse it to extract useful information.
The end goal is to use the 'useful' information to plot graphs using HTML5 Canvas.
I need some direction with how to make the query? because when I read this forum, it is recommended that client-side query is 'bad' for a plethora of reasons.
Since most of my stuff is happening in the client side... few things in C# asp.net...how do I proceed?
It is also important to note that the web application should be accessible via the internet. outside the local network.
Does it make sense to Call a Web Service from the Client Side Using the AJAX Extension Toolkit??
You must handle it server side. Think about the ajax request as a simple POST or GET in the format of ?member_id=123&time=321 pointed at your handler file.
In your handler file you can construct your query from the request variables, execute it, and give a response by printing to the screen in either JSON or XML format.
Take a look here:
http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/jQuery.getJSON/

Does d3.json() support authentication? If not, what other JavaScript options are available for JSON retrieval?

I am developing an application that needs to gather information from GitHub, so I began looking at their API. My initial thought was to use the d3.json() function to get the data (because it's simple and has done good things for me in the past), but there doesn't appear to be a way for me to authenticate with that function. For example, $ curl -u "username" https://api.github.com is given as an example of basic authentication (from GitHub API--obviously they use curl for their examples).
So, is there a way to do authentication with the d3.json() function? And if not, what are my other options to get the JSON with JavaScript?
Thanks!
Edit:
I'm experimenting now with using jQuery's getJSON method as shown here, because I started getting the error "XMLHttpRequest cannot load url Origin url is not allowed by Access-Control-Allow-Origin." Of course, the switch doesn't help with the ability to authenticate, but I can at least get the public data (which is most).
Edit #2:
Has anyone experimented with michael/github or fitzgen/github-api? I'm going to start looking into those.
If you have a PHP script which echos JSON, you can do all authentication server-side. Note that you can also send a GET request to your PHP script, so the way you call your script can be dynamic.

Simple HTML POST without any server scripting, can be done using JS

I want to pass some textbox value strictly using POST from one html page to another...
how can this be done without using any server side language like asp.net or php
can it be done using javascript??
thnx
You can't read POST data in any way on javascript so this is not doable.
Here you can find similar questions:
http://forums.devshed.com/javascript-development-115/read-post-data-in-javascript-1172.html
http://www.sitepoint.com/forums/showthread.php?454963-Getting-GET-or-POST-variables-using-JavaScript
This reading can also be interesting: http://en.wikipedia.org/wiki/POST_%28HTTP%29
This expecially suggests why this answer (wikipedia is the source):
GET
Requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect.
(This is also true of some other HTTP methods.)[1] The W3C has
published guidance principles on this distinction, saying, "Web
application design should be informed by the above principles, but
also by the relevant limitations."[10] See safe methods below.
POST
Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request.
This may result in the creation of a new resource or the updates of
existing resources or both.
POST data is added to the request. When you do a GET request the data is added to the url, and that's why you can access it through javascript (and that's why it's not parsed and you have to do it manually). Instead, POST send data directly into the http requests, which is not seen in any way by the html page (which is just a part of what is sent through the http request).
That said, only server side language will receive the full HTTP request, and definitely you can' access it by javascript.
I'm sorry but that is the real answer

Categories