Importing JSON via Google Spreadsheet API - javascript

I just want to pull my spreadsheet into an app/website. Ideally, I'd like it to be private, but first I'm trying to bring in the data with the spreadsheet "available to the public" and "published to the web".
$.ajax({
type: 'GET',
url: 'http://spreadsheets.google.com/feeds/cells/' + spreadsheetKey + '/od6/public/full?alt=json',
success: function(data){
alert("success");
}
});
This always results in:
"You do not have view access to the spreadsheet. Make sure you are properly authenticated."
I've tried without ?alt=json, with 'list' instead of 'cells', and with 'values' instead of 'full'. Nothing works.
Also, is there a way to pass the access token into this call? I'm authenticating via Google Sign-In and allowing for Spreadsheet API scope. I've tried &accessToken=xxx and &access_token=xxx. The documentation doesn't have anything for Javascript.

For Javascript access to a private spreadsheet, you'll need the Javascript library here: https://code.google.com/p/google-api-javascript-client/wiki/Authentication That allows you to use OAuth2.0 which allows you to access a private Google Spreadsheet. See the answer under Google Spreadsheets API with OAuth 2.0 using Javascript for a full description.
For the access token, the syntax is:
&access_token=xxx The relevant details for Javascript is under the Protocol heading in the Google Spreadsheet API, but it isn't that helpful I've found.
To get JSON do the following:
var url = 'https://spreadsheets.google.com/feeds/list/' + urlLocation + '/od6/private/full?alt=json-in-script&access_token=' + token + '&callback=?';
$.getJSON(url, function(data) {
//do stuff with data here
});

Related

Making a GET request that uses POST method - Javascript to C# API

I have a situation where I'm required to encrypt data in flight from a JavaScript based application (Chrome Extension popup.html) to an API hosted in a .NET MVC website(C#).
I can run the request as a GET but project requirements make it necessary to encrypt the parameters I'm sending. For example if I was searching for all people named 'John' I need to encrypt 'John' in flight.
My JavaScript application is using jsencrypt and a RSA (public) key provided by the website in other APIs that work quite well to return counts.
If my GET version of the link looks like this:
<span class="person" id="personList">Person: '+ query +'</span>
On the .NET website end, this request is processed into a view that generates a table using a database call. As you can see in my link the results are populated onto a new tab in the browser.
How would you recommend changing it to calling a POST method and getting the same result as a GET?
EDIT
I tried to employ an AJAX function to make the POST but it doesn't like the data element:
event.preventDefault();
$.ajax({
url: repurl + 'Persons/Search',
timeout:30000,
type: "POST",
data: {body: encryptedmsg},
success : function(msg) {
if (msg.ws_resultat.result_ok == true)
{
alert('ok');
}
else
{
alert('some thing went wrong, plz try again');
}
}
});
});```

How to get all the repositories for a particular user?

I am trying the extract the various repository names for a particular user and populate a combobox on a html page. I am able to extract only one repository name. How can I get all the names? The code I have so far:
$.ajax({
url:"https://api.bitbucket.org/2.0/repositories/abc",
username: "palld#bdbd.in",
password: "abcdef123456",
success: function(data){
console.log(data);
},
error: function(){
console.log("Connection did not go through");
},
type: 'GET'
});
Writing similar code in Java and python worked and I was able to see all the repository names. Any help would be appreciated.
The result is as below:
Edit:
It appears that Bitbucket will send you some data even when you are not authenticated to their API. I suspect that there is no authentication request sent to you by the API and jQuery simply does not send the username and password when not asked for.
This code explicitly send the authentication data to the API:
var reposUsername = "OWNER_OF_REPOS";
var authUsername = "YOUR_USERNAME";
var authPassword = "YOUR_PASSWORD";
$.ajax({
url:"https://api.bitbucket.org/2.0/repositories/" + reposUsername,
success: function(data){
console.log(data);
},
error: function(){
console.log("Connection did not go through");
},
type: 'GET',
headers: {
'Authorization': "Basic " + btoa(authUsername + ":" + authPassword)
}
});
(I'm 100% sure that this code works as I've tested it a few minutes ago with my own Bitbucket account).
Note: please be aware that storing your credentials in the code is something you should not do, so think twice before you release your code/application the the public.
Obsolete answer:
Just look at the documentation Bitbucket provides to you (although, the example response looks kind of weird).
Assuming your data object is already a JSON parsed object, you should be able to access your respositiories like this (Edit: code adjusted the the provided screenshot):
data.values
Parse the JSON response. If it works from Python or Java then it must be something to do with the way you are handling the response in JavaScript. Perhaps you are not parsing it, which you need to do to convert it into a proper JSON object containing all the elements you want.
success: function(data){
console.log(JSON.parse(data));
},

How to access HP ALM using REST and local javascript?

I just want to access ALM via local written javascript js in the browser (IE11, Firefox) via the REST API but I can not login. Here is my code for requesting the LWSSO cookie via jquery:
var auth = btoa(USER+":"+PASSWORD);
$.ajax({
type: "POST",
url: https://alm.xxx.net/qcbin/authentication-point/j_spring_security_check,
headers: {
"Authorization": "Basic " + auth
},
success : function(data) { },
});
The response header contains:
https://alm.xxx.net/qcbin/authentication-point/login.jsp;jsessionid=1gfsdk4pn525f1ur55e2x2zzte?login_error
With OTA/directX object everything works fine but I want to use the REST API via javascript. Can anyone help me?
First of all; which version of ALM are you using? Second, I think you are using the wrong URL for the authentication point. According to the documentation (for ALM 12.01) it should be https://alm.xxx.net/qcbin/authentication-point/authenticate.
Also, the HTTP method you use should be GET, not POST.
I noticed that you are using https in the URL, so I assume your instance of ALM is set up with that?

How can I manage Google account's contacts through JavaScript?

I'm trying to manage Google account contacts through JavaScript programs. When I'm trying to delete contacts through JavaScript, this error occurs: "Network Error: 405 Not Allowed Method."
Here is My Code:
function deleteContacts() {
$.ajax({
type: 'DELETE',
url: 'https://www.google.com/m8/feeds/contacts/default/full/{client_Id}?access_token=' + tokenId,
headers: {
'If-Match': '*',
'Gdata-version': '3.0'
},
dataType: 'jsonp',
data: {},
success: function (data) {
console.log("response: " + data)
}
});
}
Please help me in this, is this possible to manage Google account's contacts through JavaScript? If it is really possible then please tell me all possibilities for managing Google account's contacts....
Is there any other JavaScript API available?
Is there any alternate solution?

I Know Google has listed solutions in java, PHP, nodes as well, and I am writing server code in Nodejs, but seems like Google client code for NodeJs in alpha version, not sure how much strong it is to manage contacts...
Make use of the google client api for javascript, Authenticate, getToken and then use Request and then execute it. Pass on the method and url as per your need. For delete purpose, pass these are its input:
method : 'DELETE',
url : '/m8/feeds/contacts/default/full/<friend id to delete>'

manipulating the geocoding webservices results through javascript?

using
http://maps.google.com/maps/api/geocode/json?address=xyz
we get a json file
I am wondering how can i maniupluate the results in javascript? How do i create the results object in javascript?
http://code.google.com/apis/maps/documentation/geocoding/index.html#JSONParsing
this doesnt really explain how they get the myJSONResult
You can use eval to parse the JSON into a JavaScript object, but this isn't recommended for security reasons. Use a JSON parser to turn the JSON string into a JavaScript object that you can manipulate.
Using eval:
myJSONResult = eval("{}");
Using the above linked parser:
myJSONResult = JSON.parse("{}");
The way you get the JSON is using an AJAX retrieval. This can be accomplished using hand coded JavaScript, but is far far easier using jQuery. Here's a quick example:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({ url: "http://maps.google.com/maps/api/geocode/json",
type: "GET",
dataType: "json",
data: { address: "1600+Amphitheatre+Parkway,+Mountain+View,+CA", sensor: "false" },
success: function(data, textStatus, XMLHttpRequest) {
console.log(textStatus);
alert(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(textStatus);
}});
});
</script>
BUT BUT BUT this will NOT work, because of the same origin policy. The way around that is to use a server side language of your choice (Perl, PHP, ColdFusion, ASP) to act as a proxy. That way the url value would be "yourproxy.php", "yourproxy.cfm", "yourproxy.asp" or whatever. That script would simply take the request it receives, act as a user agent to send the request to Google and retrieve the response (aka the URL that is the url value in the code above), and send out the results to your script.
The jQuery library handles the JSON processing for you, or you can use the information provided by Bob along with the hand rolled AJAX listed above. Note that hand rolled AJAX will need the same proxy solution to be able to get information from Google.
Also note that the Geocoding API you linked to is not meant for lots of dynamic queries. They lead you to the API V2 Client Geocoder, the API V3 Client Geocoder, and the Maps API for Flash Client Geocoder.

Categories