CODE
var sAuthorizationHeader = 'THIS IS THE VALUE THAT RETURNS FROM MY WEB APP';
var sUrl = 'http://mail.yahooapis.com/ws/mail/v1.1/jsonrpc';
var sApiMethod = 'ListMessages';
var params = 'fid=inbox&numMid=10';
var oAjax = new XMLHttpRequest();
oAjax.open("POST", url, true);
oAjax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oAjax.setRequestHeader("Content-length", params.length);
oAjax.setRequestHeader("Authorization", "sAuthorizationHeader");
oAjax.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if(oAjax.readyState != 4)
return;
if (oAjax.status != 200){
/** report error code /**/
return;
}
/**display the emails:/**/
}
http.send(params);
i improved the snippet above, it looks like this now:
CODE
function getYahooEmails(){
var aParams = [{'fid':'inbox','startInfo':0,'numInfo':10}];
var oRequest = {'method':'ListMessages','params': aParams};
var sRequest = json_encode(oRequest); //i took json_encode from here: http://phpjs.org/functions/json_encode:457
var sUrl = 'http://mail.yahooapis.com/ws/mail/v1.1/jsonrpc';
var sHeader = 'OAuth oauth_nonce="f65670481f2282ddc82607e148de374a",oauth_timestamp="1272050828",oauth_version="1.0",oauth_signature_method="HMAC-SHA1",oauth_consumer_key="MYKEY",oauth_token="TOKEN",oauth_signature="SIG"'; //this value is from my web page application
var oAjax = new XMLHttpRequest();
oAjax.open("POST",sUrl,true);
oAjax.setRequestHeader("Content-Type", "application/json");
oAjax.setRequestHeader("Accept", "application/json");
oAjax.setRequestHeader("Authorization", sHeader);
oAjax.setRequestHeader("Connection", "close");
oAjax.onreadystatechange=function(){
if(oAjax.readyState != 4) return;
if(oAjax.status != 200) return;
document.getElementById('result').innerText = oAjax.responseText;
}
oAjax.send(sRequest);
}
i use fiddler to see the call:
my request header:
CODE
POST /ws/mail/v1.1/jsonrpc HTTP/1.1
Accept: application/json
Accept-Language: he
Pragma: no-cache
Authorization: OAuth oauth_nonce="f65670481f2282ddc82607e148de374a",oauth_timestamp="1272050828",oauth_version="1.0",oauth_signature_method="HMAC-SHA1",oauth_consumer_key="MYKEY",oauth_token="TOKEN",oauth_signature="SIG"
Content-Type: application/json
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)
Host: mail.yahooapis.com
Content-Length: 117
Connection: Keep-Alive
this is the response:
CODE
HTTP/1.1 500 Internal Server Error 88
Date: Fri, 23 Apr 2010 19:27:44 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Vary: Accept-Encoding
Content-Type: application/json
Cache-Control: private
Age: 0
Transfer-Encoding: chunked
Connection: keep-alive
Server: YTS/1.17.23
{"result":null,"error":{"code":"Client.FolderIdDoesntExist","message":"Folder ID doesn't exist.","detail":null}}
what can be the problem?
when i do server to server call i use the same params
thanks
Elad