首页 \ 问答 \ 使用node.js向Google API发出http请求(Making http request to Google API with node.js)

使用node.js向Google API发出http请求(Making http request to Google API with node.js)

我正在尝试向Google AnalyticsAPI提出请求。 我正在使用Passport.js来授权用户和此库发出请求。

我得到了一个很好的回复来自谷歌,但我的问题是,请求继续进行,直到它超时,即使我收到了repsonse。 请求保持不运行,直到我有时间。

我究竟做错了什么?

这是我的代码:

request('https://www.googleapis.com/analytics/v3/management/accounts?access_token=' + access_token,  function (error, response, body) {
    if(error){
      console.log(error);
    }else{
      console.log(repsonse);
    }
});

I'm trying to make a request to the Google Analytics API. I'm using Passport.js to authorize the user and this library to make requests.

I get a nice repsonse from Google but my problem is that the request keeps on going until it times out even after I've received the repsonse. The request keeps un running until I get a time out.

What am I doing wrong?

Here is my code:

request('https://www.googleapis.com/analytics/v3/management/accounts?access_token=' + access_token,  function (error, response, body) {
    if(error){
      console.log(error);
    }else{
      console.log(repsonse);
    }
});

原文:https://stackoverflow.com/questions/18048950
更新时间:2021-09-19 19:09

最满意答案

从自由形式字段中解析好名字并非易事......

我建议采用双重方法。

识别常见模式,即您可能会找到类似这样的电话号码

Where IsNumeric( Replace(Field,'-','')=1

你可能会用。识别单个名字

Where charindex(' ',trim(field))=0

等等

一旦你确定了它们,写代码就会尝试拆分它们......

因此,您可以使用上面的代码和以下WHERE子句

  select SUBSTRING(FULL_NAME, 1, CHARINDEX(' ', FULL_NAME) - 1) AS FirstName,
         SUBSTRING(PRQ_BP_CONTACT_NAME, CHARINDEX(' ', FULL_NAME) + 1, 500) 
         AS LastN
  from [dbo].[TABLE]
  where charindex(' ',trim(field))>0 and Where IsNumeric( Replace(Field,'-','')=0

使用WHERE子句来(a)确保只获得可以解析的记录,以及(b)帮助识别您需要手工完成的奇怪案例......

祝你好运


Parsing good names from free form fields is not an easy task...

I would suggest a dual approach.

Identify common patterns, i.e. you might find phone number with something like this

Where IsNumeric( Replace(Field,'-','')=1

and you might identify single names with

Where charindex(' ',trim(field))=0

etc.

Once you've identified them, the write code to attempt to split them...

So you might use the code you have above with the following WHERE clause

  select SUBSTRING(FULL_NAME, 1, CHARINDEX(' ', FULL_NAME) - 1) AS FirstName,
         SUBSTRING(PRQ_BP_CONTACT_NAME, CHARINDEX(' ', FULL_NAME) + 1, 500) 
         AS LastN
  from [dbo].[TABLE]
  where charindex(' ',trim(field))>0 and Where IsNumeric( Replace(Field,'-','')=0

Use the WHERE clauses to (a) make sure you only get records you can parse and (b) help identify the oddball cases you'll like need to do by hand...

Good luck

相关问答

更多
  • 如果第一个名字在A2中,请将B2中的此公式复制下来 =MID(A2&" "&A2,FIND(" ",A2)+1,LEN(A2)-1) If the first name is in A2 try this formula in B2 copied down =MID(A2&" "&A2,FIND(" ",A2)+1,LEN(A2)-1)
  • 假设您的输入是FirstName Name Name LastName,请拆分字符串并使用第一个和最后一个索引: String bigName = "John McDonalds Harris" String[] names = bigName.split(" "); System.out.println(String.format("FirstName: %s : LastName: %s", names[0], names[names.length-1])); 它将打印:FistName:约翰:姓氏 ...
  • 您的派生列表达式应如下所示: FINDSTRING(TRIM(FULLNAME)," ",1) == 0 ? FULLNAME : SUBSTRING(TRIM(FULLNAME),1,FINDSTRING(TRIM(FULLNAME)," ",1)) Your derived column expression should be like this : FINDSTRING(TRIM(FULLNAME)," ",1) == 0 ? FULLNAME : SUBSTRING(TRIM(FULLNAME) ...
  • 荣誉布拉德利牧师回答这个问题。 在模板中使用this技巧就可以实现。 的index.html