本文介绍了获取项目从Teamweek jQuery中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让该计划从 Teamweek 在我的js的应用程序。 ( API

 函数get_teamweek_planning()
{
    VAR api_url ='https://teamweek.com/api/v2/',
        API_KEY ='1234567',
        对象类型='项目';

    $阿贾克斯(
    {
        网址:api_url + API_KEY +/projects.json,
        键入:GET,
        数据类型:JSONP,
        缓存:假的,
        数据: {},

        成功:函数(响应){
            的console.log(回应:,响应);
        }
    });
}
 

这会返回一个403(禁止)。这是记录并表示认证失败。但是,如何解决呢?

解决方案

 函数get_teamweek_planning()
{
    VAR api_url ='https://teamweek.com/api/v2/',
        ACCOUNT_ID ='<您的帐户ID>';

    $阿贾克斯(
    {
        网址:api_url + ACCOUNT_ID +/projects.json,
        beforeSend:函数(要求)
        {
         request.setRequestHeader('授权','承载'+ BTOA(<您的API令牌GT;'))
        },
        键入:GET,
        数据类型:JSONP,
        缓存:假的,
        数据: {},

        成功:函数(响应){
            的console.log(回应:,响应);
        }
    });
}
 

如果您需要的资料使用本网页,不仅为自己的话就不要硬code令牌......

I'm trying to get the planning from Teamweek in my js app. (API)

function get_teamweek_planning()
{
    var api_url     = 'https://teamweek.com/api/v2/',
        api_key     = '1234567',
        object_type = 'projects';

    $.ajax(
    {
        url: api_url + api_key + '/projects.json',
        type: 'GET',
        dataType: 'jsonp',
        cache: false,
        data: {},

        success:function(response){
            console.log('response:', response);
        }
    });     
}

This returns a 403 (forbidden). This is documented and means authentication fails. But how do i fix it?

解决方案
function get_teamweek_planning()
{
    var api_url     = 'https://teamweek.com/api/v2/',
        account_id  = '<your account id>';

    $.ajax(
    {
        url: api_url + account_id + '/projects.json',
        beforeSend: function (request)
        {
         request.setRequestHeader('Authorization', 'Bearer ' + btoa('<your api token>'))
        },
        type: 'GET',
        dataType: 'jsonp',
        cache: false,
        data: {},

        success:function(response){
            console.log('response:', response);
        }
    });     
}

If your're using this on a page that isn't only for yourself then do not hard code your token...

这篇关于获取项目从Teamweek jQuery中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 15:12