0

I want to integrate Windows Azure Services within the app created in Titanium, same as we use to do with eclipse for Android. I am newbie working with Titanium. Please help me providing some useful links to get started with.

4

3 回答 3

1

我找到了这些:http: //developer.appcelerator.com/question/149494/using-titanium-httpclient-to-access-windows-azure-mobile-services-rest-api

由于这是一个 JavaScript 库,它应该会有所帮助。不过可能有点老了。 http://azureblobstoragejs.codeplex.com/

于 2013-07-29T13:31:37.883 回答
1

这就是我使用 REST API 获取数据的方式。

function getWebserviceURL() {

    return "https://database_name.azure-mobile.net/tables/";
}

function getCountryMasterData() {

    var xhr = Titanium.Network.createHTTPClient();
    xhr.onerror = function(e)
    {
        alert(e.toString);
    };
    xhr.onload = function() {
        alert(this.responseText);
    };
    var request_url = getWebserviceURL() + "table_name";
    xhr.open('GET', request_url);
    xhr.setRequestHeader("Accept","application/json");
    xhr.setRequestHeader("X-ZUMO-APPLICATION", "APP KEY");
    xhr.setRequestHeader("Host", "database_name.azure-mobile.net");
    xhr.send();
}
于 2013-08-02T12:57:31.020 回答
0

编辑:

我为 Windows Azure 移动服务编写了 Titanium SDK。在这里查看:https ://github.com/rfaisal/tiny-azuresdk-titanium

原答案:

首先登录facebook获取access_token(我们称之为authorization_grant):

var fb=require('facebook');
fb.appid = 000000000000000; //replace this with your facebook app id
fb.permissions = ['email']; // add or remove permissions
fb.addEventListener('login', function(e) {
    if (e.success) {
        Ti.API.info('authorization_grant: '+fb.getAccessToken()); // prints to console, save for future use
    }
});
fb.authorize();

然后,从 authorization_grant 获取 access_token(不是 facebook,而是 azure):

var authorization_grant = 'CAAHn34BO0R0BABtJyxdrZCQzakdmgJZBoQa0U...'; //saved from previous step
var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(30000);
xhr.onload=function() {
    Ti.API.info('access_token: '+JSON.parse(this.responseText).authenticationToken); // save this for requesting protected resource
};
xhr.onerror= function() {
    Ti.API.info('Auth Failure response: '+this.responseText);
};
xhr.open('POST', 'https://my_resource_auth_server.azure-mobile.net/login/facebook');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.send({
    "access_token" : authorization_grant
});

最后通过access_token获取受保护的资源:

var access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsI...'; //saved from previous step
var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(30000);
xhr.onload=function() {
    Ti.API.info('Protected Resource: '+this.responseText);
};
xhr.onerror= function() {
    Ti.API.info('Error response: '+this.responseText);
};
xhr.open('GET', 'https://my_resource_auth_server.azure-mobile.net/api/some_resource');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("X-ZUMO-AUTH", access_token); // this is the magic line
xhr.send();

要获取需要应用程序级别访问的资源,请添加一个名为 X-ZUMO-APPLICATION 的标头并传递从 Azure 网站获得的应用程序密钥。同样,要访问需要管理员级别访问权限的资源,请将您从 Azure 网站获取的移动服务主密钥作为 X-ZUMO-MASTER 标头传递。

这里遵循的 oAuth 流程: 在此处输入图像描述

原文发表文章:https ://rfaisalblog.wordpress.com/2014/03/01/oauth-flow-for-mobile-apps-with-an-external-identity-server/

于 2014-03-01T22:26:47.790 回答