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));
},
Related
Ajax request is executing, but it returns not curent_day variable but null.
Js:
$.ajax({
url: 'planing/next-day',
data: {new_curent_day: $('.owl-item.center .slide_day').text()},
dataType: 'json',
type: 'POST',
success: function(curent_day) {
alert(curent_day);
},
error: function(xhr, status, error) {
alert(xhr.responseText + '|\n' + status + '|\n' +error);
}
});
Controller:
public function actionNextDay() {
if (Yii::$app->request->isAjax){
$this->planing_model->curent_day = Yii::$app->request->post('new_curent_day');
return Json::encode($this->planing_model->curent_day);
}
}
May be the problem is your are sending the POST data as JSON so your not able get it through
Yii::$app->request->post('new_curent_day');
Try this they have updated JSON parser set and to get the JSON value through yii.
Error in accessing post json data in yii2
Use the Javascript console and debugger in your browser to see what $('.owl-item.center .slide_day') contains. Make your API endpoint log what it gets in the post variables.
The typos in variable names make me worry that you might refer to the wrong thing. planing has two n's, curent has two r's. This code looks consistent at least but if I came across this code I would suspect current and curent got mixed up.
I've already had a look around and i can't seem to find an answer to this, I'm needing my access token to last longer than the 2 hours that it currently does. unless you are able to suggest another method of getting a json result. Thanks
Heres my code
//first define a function
//include two files where rows are loaded
//1.js
$.ajax({
type: 'GET',
crossDomain: true,
dataType: 'json',
url: 'https://graph.facebook.com/v2.3/147733805246675?fields=posts&access_token=CAACEdEose0cBALZA1JuPZCO5MW3WZAX2ERa3RJ7PA5QKawTRGH9Yg0tdv4ENVJeZAqFchh9mNJuHu75gKv6QkHj63ezAZBGUm1OnpHWurJM4Aa0J71hFsCr27ZCSz43IuYs7QoBomtHVJCiex6ZBRZAovNybDf5XhfyaPNt5CHhvAhnoSZAXFO8q8c2na1ndztlp1zY2ftvsc9QVZCboEwdLAQnZA4zejYvM7kZD',
success: function(json) {
//var json = $.parseJSON(data);
for (var i = 0; i < json.posts.data.length; i++) {
var section = json.posts.data[i].message;
$("#tableid").append("<tr><td style='width:70px'><img id='theImg' src='img/fb.png'/></td><td><b>" + section +
"</b></td></tr>");
}
},
error: function(error) {
console.log(error);
}
});
The Javascript SDK will handle all token-related logic for you. Why do you want to have a long-lived token in the browser?
You should use the Javascript SDK and the features it provides. The only use-case to generate long-lived tokens yourself is if you want to make API calls from your server.
Since extending and token involves sending over your App Secret, you should not do that in the browser; your app secret should only be on your server.
I'm using the Instagram api and have successfully retrieved an access_token, along with using HTML5 geolocation to retrieve a user's location. This data is then used to construct the string to access the instagram endpoint:
https://api.instagram.com/v1/media/search" + coordsquery + "&access_token=" + access
I have set my redirect uri from Instagram as http://localhost/explorer and my request for access_token in my application is var redirect = "http://localhost/explorer";
However I still get the error. I read that Chrome has a bug or something with localhost and making calls like this so I tried in firefox. Same deal.
I also read somewhere about appending ?callback=? to the GET request url. Also no dice.
I still don't know what was wrong with my original:
$.get(querystring, function( data ) {
console.log(data);
});
but I ended up trying this:
$.ajax({
type: "GET",
dataType: "jsonp",
url: querystring,
success: function(data) {
console.log(data);
}
});
and it worked just fine.
If someone could possibly explain why the second approach worked where the first failed I'd be forever grateful.
I am playing with Google API in javascript. I managed to get a list of my contact with the following code :
$.ajax({
url: 'https://www.google.com/m8/feeds/contacts/default/full?access_token=' + access_token + '&alt=json',
method: 'GET',
error: function(error) {
alert('An error has occured during contact creation.');
},
success: function(data, status){
console.log(data);
}
});
I tried to add a contact by changing GET to POST and adding my contact data in the request body. But as soon as I add a data attribute, or change GET to POST, the server answers me the really annoying "No 'Access-Control-Allow-Origin" error.
Any idea?
I am following this documentation : https://developers.google.com/google-apps/contacts/v3/?csw=1#creating_contacts
Thanks a lot
It is possible to do this from the browser, although not obvious at all.
Based on this SO answer, we learn that there is method called gapi.client.request that can be used for this (instead of jQuery's $.ajax).
Accordingly, for editing we can do:
gapi.client.request({
method : 'PUT',
path:'m8/feeds/contacts/default/full/<contactId>/<editRevisionFromGET>',
body : {"version":"1.0","encoding":"UTF-8","entry": ...},
callback : function(data) {
console.log(data);
}
});
The important parts for editing in here are:
send back the entire entry you got before from a read
use the current ID given at the end of the URL in the entry.link element with relation type edit (or you'll get a HTTP Status 409 - Conflict)
Side note:
Notice that these requests actually are done to https://content.googleapis.com/ ...
From some quick tests, it seems you can do ?all? requests just to that URL instead of google.com, and then CORS issues disappear.
i am using the third party api for getting the Address on the basis of postcode . it returns the json data .
below is the api that i am calling but i am not sharing the datakey that i am using .
i am accessing this in jquery not using any server side scripting languages .
$.getJSON("http://www.simplylookupadmin.co.uk/JSONservice/JSONSearchForAddress.aspx?datakey=data key &postcode=CM129BY&callback=?", function () {
alert("aaa");
});
also using the other code like
// jQuery.ajax({
// type: 'GET',
// url: 'http://www.simplylookupadmin.co.uk/JSONservice/JSONSearchForAddress.aspx?datakey=data key&postcode=CM129BY?jsoncallback=?',
// dataType: 'json',
// success: function (data) {
// alert('success');
// }
// });
but i am getting the error
Error: invalid label
Source File: http://www.simplylookupadmin.co.uk/JSONservice/JSONSearchForAddress.aspx?datakey=datakey&postcode=CM129BY&callback=jQuery17209661092291729644_1335505434728&_=1335505437637
Line: 2, Column: 2
Source Code:
"found":"1",
please advice its very urgent
Thanks
naveen Kumar GUpta.
I think you may be missing any Quotes.Please check it once again.
I think the postcode you are searching is not found in the Database.
I got it.
It is the JSON result string is invalid as JSON, open the URL http://www.simplylookupadmin.co.uk/JSONservice/JSONSearchForAddress.aspx?datakey=data key &postcode=CM129BY&callback=? with web browser I got the content:
{
"found":"1",
"credits_display_text":"Cannot find FULL PAF license(credits or users)",
"accountadminpage":"https://www.simplylookupadmin.co.uk/WebAccountLogin.aspx?doid=1&coid=30&Pay=yes",
"errormessage":"Search denied! Cannot find FULL PAF license(credits or users)",
"maxresults":"0",
"recordcount":"0",
"records"]}
At the end of it, "]" is not needed.