Вопрос

So I keep Receiving an error when I'm trying to use OAuth with Asana's API. The error I'm receiving is "Error no route found". What am I doing wrong? I know that the request is most likely correct, but I believe it returns a hashed URL and i'm supposed to unhash it. This is sample code I am using from a Facebook OAuth though, so perhaps the code is incorrect and facebook api specific.

Here is my code:

$(function () {

    checkHashLogin();

    $('#signon').click(function () {
        asanaLogin();
    });
})
}); 

var appID = ****************;

function asanaLogin() {
    var path = 'https://app.asana.com/-/oauth_authorize';
    var queryParams = ['client_id=' + appID,
    'redirect_uri=' + window.location,
    'response_type=token'];
    var query = queryParams.join('&');
    var url = path + query;
    window.location.replace(url);
}
function checkHashLogin() {
if (window.location.hash.length > 3) {
    var hash = window.location.hash.substring(1);
    if(hash.split('=')[0] == 'access_token')
    {
        var path = "https://app.asana.com/-/oauth_authorize";
        var queryParams = [hash, 'callback=displayUser'];
        var query = queryParams.join('&');
        var url = path + query;

        //use jsonp to call the graph
        var script = document.createElement('script');
        script.src = url;
        document.body.appendChild(script);
    }

}
} 



function displayUser(user) {
    setTimeout(function () { }, 1000);
    if (user.id != null && user.id != "undefined") {
       //Do Stuff
    }
    else {
        alert('user error');
    }
}

Here is a photo of my app credentials. My redirect location is just local because I am not hosting it on a server yet.

app details

Это было полезно?

Решение

Looks like you're doing url = path + query when you might need to do url = path + "?" + query - the query string isn't separated, which means you end up requesting a path like https://app.asana.com/-/oauth_authorizeclientId=... which isn't recognized: hence, "no route found".

Hope that helps!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top