Picasa Web API
Hej EksperterHåber virkelig der er nogle som kan hjælpe....
Jeg er ved at lave et online fotoalbum hvor brugere kan logge på og vise/uploade billeder til deres Picasa konto.
Visning fungere godt med kan ikke oprette eller rette i album, tags mv... Jeg er ikke helt sikker på hvordan dette skal gøres... Men her er et forsøg.
--------------------------------------------------------------------
var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?';
var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
var CLIENTID = '???????';
var REDIRECT = 'http://mhe-invest.dk/oauth2callback';
var LOGOUT = 'http://accounts.google.com/Logout';
var SCOPE = 'https://www.googleapis.com/auth/userinfo.profile';
var TYPE = 'token';
var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE;
var acToken;
var tokenType;
var expiresIn;
var user;
var loggedIn = false;
function login() {
var win = window.open(_url, "windowname1", 'width=800, height=600');
var pollTimer = window.setInterval(function() {
console.log(win);
console.log(win.document);
console.log(win.document.URL);
if (win.document.URL.indexOf(REDIRECT) != -1) {
window.clearInterval(pollTimer);
var url = win.document.URL;
acToken = gup(url, 'access_token');
tokenType = gup(url, 'token_type');
expiresIn = gup(url, 'expires_in');
win.close();
validateToken(acToken);
}
}, 500);
}
function validateToken(token) {
$.ajax({
url: VALIDURL + token,
data: null,
success: function(responseText){
//getUserInfo();
uploadPhoto();
loggedIn = true;
$('#loginText').hide();
$('#logoutText').show();
},
dataType: "jsonp"
});
}
function getUserInfo() {
$.ajax({
url: 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + acToken,
data: null,
success: function(resp) {
user = resp;
console.log(user);
$('#uName').text('Welcome ' + user.id);
$('#imgHolder').attr('src', user.picture);
},
dataType: "jsonp"
});
}
function createAlbum() {
var json_Album_URI = "https://picasaweb.google.com/data/entry/api/user/117643215447718839867?access_token=" + acToken;
var albumdata = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gphoto='http://schemas.google.com/photos/2007'><title type='text'>Trip To Italy</title><summary type='text'>This was the recent trip I took to Italy.</summary><gphoto:location>Italy</gphoto:location><gphoto:access>public</gphoto:access><gphoto:commentingEnabled>true</gphoto:commentingEnabled><gphoto:timestamp>1152255600000</gphoto:timestamp><media:group><media:keywords>italy, vacation</media:keywords></media:group><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album'></category></entry>";
$.ajax({
type : 'POST',
url: json_Album_URI,
data : albumdata,
dataType: 'application/xml',
success:function(data){alert("inside"+JSON.stringify(data));}
});
}
/*
function createAlbum() {
var method = 'GET';
var url = 'https://picasaweb.google.com/data/entry/api/user/117643215447718839867?access_token='+acToken;
var albumdata = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gphoto='http://schemas.google.com/photos/2007'><title type='text'>Trip To Italy</title><summary type='text'>This was the recent trip I took to Italy.</summary><gphoto:location>Italy</gphoto:location><gphoto:access>public</gphoto:access><gphoto:commentingEnabled>true</gphoto:commentingEnabled><gphoto:timestamp>1152255600000</gphoto:timestamp><media:group><media:keywords>italy, vacation</media:keywords></media:group><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album'></category></entry>";
var albumdata = {
"entry": {"xmlns": "xmlns='http://www.w3.org/2005/Atom"},
"title": [{
"type": "text"},"Album title"
]
};
var albumdata = "<entry><title type='text'>Trip To Italy</title></entry>";
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.responseType = "jsonp";
xhr.setRequestHeader("GData-Version", "2");
//xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
xhr.setRequestHeader("Content-Type", "application/xml");
xhr.setRequestHeader("Authorization", "AuthSub token=" + acToken);
xhr.setRequestHeader("Content-length", albumdata.length);
xhr.setRequestHeader("Connection", "close");
xhr.onreadystatechange = function(data) {
alert(xhr.readyState+"-:-"+JSON.stringify(data)+":"+xhr.status);
if (xhr.readyState == 4) {
alert("Success"+":"+xhr.responseXML+":"+acToken);
}
};
xhr.send(albumdata);
}
*/