pat310 / google-trends-api

An API layer on top of google trends
https://www.npmjs.com/package/google-trends-api
MIT License
889 stars 176 forks source link

Error when adding geo to region query #77

Closed nicholaai closed 7 years ago

nicholaai commented 7 years ago

I've been pulling my hair out about this, so hopefully this helps someone else out haha.

When using 4.2.1, if you add a geo field to an interest by region query, you'll get an error. I downgraded to 4.1.0 like I had in my other project and the error no longer occurs and you get the expected response.

Params: keywords: ['Apple, Dell, Lenovo'], resolution: 'STATE', geo: 'US', startTime, endTime

{ message: 'Available widgets does not contain selected api type', requestBody: ')]}\'\n{"widgets":[{"request":{"time":"2017-08-06 2017-09-05","resolution":"DAY","locale":"en-US","comparisonItem":[{"geo":{"country":"US"},"complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Dell"}]}},{"geo":{"country":"US"},"complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Lenovo"}]}},{"geo":{"country":"US"},"complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Apple"}]}}],"requestOptions":{"property":"","backend":"IZG","category":0}},"lineAnnotationText":"Search interest","bullets":[{"text":"Dell"},{"text":"Lenovo"},{"text":"Apple"}],"showLegend":false,"showAverages":true,"helpDialog":{"title":"Interest over time","content":"Numbers represent search interest relative to the highest point on the chart for the given region and time. A value of 100 is the peak popularity for the term. A value of 50 means that the term is half as popular. Likewise a score of 0 means the term was less than 1% as popular as the peak."},"token":"APP6_UEAAAAAWbDDbIM2RzHuiv6T5tOW8JepdJT2xNOx","id":"TIMESERIES","type":"fe_line_chart","title":"Interest over time","template":"fe","embedTemplate":"fe_embed","version":"1","isLong":true,"isCurated":false},{"request":{"geo":{"country":"US"},"comparisonItem":[{"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Dell"}]}},{"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Lenovo"}]}},{"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Apple"}]}}],"resolution":"REGION","locale":"en-US","requestOptions":{"property":"","backend":"IZG","category":0}},"geo":"US","resolution":"provinces","searchInterestLabel":"Search interest","displayMode":"regions","showLegend":false,"helpDialog":{"title":"Interest by subregion","content":"See which term ranked highest in each region during the specified time frame. Values are scaled from 0 to 100, where 100 is the region with peak popularity, a value of 50 is the region where the term is half as popular, and a value of 0 means that term was less than 1% as popular as the peak."},"bullets":[{"value":"Dell","color":"PALETTE_COLOR_1"},{"value":"Lenovo","color":"PALETTE_COLOR_2"},{"value":"Apple","color":"PALETTE_COLOR_3"}],"token":"APP6_UEAAAAAWbDDbJd-1wv45UK9aeSmjHDehgtDHXQx","id":"GEO_MAP","type":"fe_geo_color_chart","title":"Interest by subregion","template":"fe","embedTemplate":"fe_embed","version":"2","isLong":true,"isCurated":false},{"text":{"text":"Dell"},"id":"TITLE_0","type":"fe_text","title":"","template":"fe_explore","embedTemplate":"fe_embed","version":"1","isLong":true,"isCurated":false},{"request":{"geo":{"country":"US"},"comparisonItem":[{"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Dell"}]}}],"resolution":"REGION","locale":"en-US","requestOptions":{"property":"","backend":"IZG","category":0}},"geo":"US","resolution":"provinces","searchInterestLabel":"Search interest","displayMode":"regions","helpDialog":{"title":"Interest by subregion","content":"See in which location your term was most popular during the specified time frame. Values are calculated on a scale from 0 to 100, where 100 is the location with the most popularity as a fraction of total searches in that location, a value of 50 indicates a location which is half as popular, and a value of 0 indicates a location where the term was less than 1% as popular as the peak. \\u003cp\\u003e\\u003cp\\u003e \\u003cb\\u003eNote:\\u003c/b\\u003e A higher value means a higher proportion of all queries, not a higher absolute query count. So a tiny country where 80% of the queries are for \\"bananas\\" will get twice the score of a giant country where only 40% of the queries are for \\"bananas\\".","url":"https://support.google.com/trends/answer/4355212"},"color":"PALETTE_COLOR_1","index":0,"bullet":"Dell","token":"APP6_UEAAAAAWbDDbGvVQcVQq51Vlkj4R-89YJYGxfHF","id":"GEO_MAP_0","type":"fe_geo_chart_explore","title":"Interest by subregion","template":"fe","embedTemplate":"fe_embed","version":"1","isLong":false,"isCurated":false},{"request":{"restriction":{"geo":{"country":"US"},"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Dell"}]}},"keywordType":"QUERY","metric":["TOP","RISING"],"trendinessSettings":{"compareTime":"2017-07-06 2017-08-05"},"requestOptions":{"property":"","backend":"IZG","category":0},"language":"en"},"helpDialog":{"title":"Related queries","content":"Users searching for your term also searched for these queries. You can sort by the following metrics: \\u003cp\\u003e* \\u003cb\\u003eTop\\u003c/b\\u003e - The most popular search queries. Scoring is on a relative scale where a value of 100 is the most commonly searched query, 50 is a query searched half as often, and a value of 0 is a query searched for less than 1% as often as the most popular query. \\u003cp\\u003e* \\u003cb\\u003eRising\\u003c/b\\u003e - Queries with the biggest increase in search frequency since the last time period. Results marked \\"Breakout\\" had a tremendous increase, probably because these queries are new and had few (if any) prior searches.","url":"https://support.google.com/trends/answer/4355000"},"color":"PALETTE_COLOR_1","keywordName":"Dell","token":"APP6_UEAAAAAWbDDbPfY4X2CiKvxmFP0NTZH5lrYJFqA","id":"RELATED_QUERIES_0","type":"fe_related_searches","title":"Related queries","template":"fe","embedTemplate":"fe_embed","version":"1","isLong":false,"isCurated":false},{"text":{"text":"Lenovo"},"id":"TITLE_1","type":"fe_text","title":"","template":"fe_explore","embedTemplate":"fe_embed","version":"1","isLong":true,"isCurated":false},{"request":{"geo":{"country":"US"},"comparisonItem":[{"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Lenovo"}]}}],"resolution":"REGION","locale":"en-US","requestOptions":{"property":"","backend":"IZG","category":0}},"geo":"US","resolution":"provinces","searchInterestLabel":"Search interest","displayMode":"regions","helpDialog":{"title":"Interest by subregion","content":"See in which location your term was most popular during the specified time frame. Values are calculated on a scale from 0 to 100, where 100 is the location with the most popularity as a fraction of total searches in that location, a value of 50 indicates a location which is half as popular, and a value of 0 indicates a location where the term was less than 1% as popular as the peak. \\u003cp\\u003e\\u003cp\\u003e \\u003cb\\u003eNote:\\u003c/b\\u003e A higher value means a higher proportion of all queries, not a higher absolute query count. So a tiny country where 80% of the queries are for \\"bananas\\" will get twice the score of a giant country where only 40% of the queries are for \\"bananas\\".","url":"https://support.google.com/trends/answer/4355212"},"color":"PALETTE_COLOR_2","index":1,"bullet":"Lenovo","token":"APP6_UEAAAAAWbDDbDIJ4rjDa5BvsflSwsUmM2oZyUVP","id":"GEO_MAP_1","type":"fe_geo_chart_explore","title":"Interest by subregion","template":"fe","embedTemplate":"fe_embed","version":"1","isLong":false,"isCurated":false},{"request":{"restriction":{"geo":{"country":"US"},"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Lenovo"}]}},"keywordType":"QUERY","metric":["TOP","RISING"],"trendinessSettings":{"compareTime":"2017-07-06 2017-08-05"},"requestOptions":{"property":"","backend":"IZG","category":0},"language":"en"},"helpDialog":{"title":"Related queries","content":"Users searching for your term also searched for these queries. You can sort by the following metrics: \\u003cp\\u003e* \\u003cb\\u003eTop\\u003c/b\\u003e - The most popular search queries. Scoring is on a relative scale where a value of 100 is the most commonly searched query, 50 is a query searched half as often, and a value of 0 is a query searched for less than 1% as often as the most popular query. \\u003cp\\u003e* \\u003cb\\u003eRising\\u003c/b\\u003e - Queries with the biggest increase in search frequency since the last time period. Results marked \\"Breakout\\" had a tremendous increase, probably because these queries are new and had few (if any) prior searches.","url":"https://support.google.com/trends/answer/4355000"},"color":"PALETTE_COLOR_2","keywordName":"Lenovo","token":"APP6_UEAAAAAWbDDbMvLoEl8Vula9Nq93Z9O53VuxyZL","id":"RELATED_QUERIES_1","type":"fe_related_searches","title":"Related queries","template":"fe","embedTemplate":"fe_embed","version":"1","isLong":false,"isCurated":false},{"text":{"text":"Apple"},"id":"TITLE_2","type":"fe_text","title":"","template":"fe_explore","embedTemplate":"fe_embed","version":"1","isLong":true,"isCurated":false},{"request":{"geo":{"country":"US"},"comparisonItem":[{"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Apple"}]}}],"resolution":"REGION","locale":"en-US","requestOptions":{"property":"","backend":"IZG","category":0}},"geo":"US","resolution":"provinces","searchInterestLabel":"Search interest","displayMode":"regions","helpDialog":{"title":"Interest by subregion","content":"See in which location your term was most popular during the specified time frame. Values are calculated on a scale from 0 to 100, where 100 is the location with the most popularity as a fraction of total searches in that location, a value of 50 indicates a location which is half as popular, and a value of 0 indicates a location where the term was less than 1% as popular as the peak. \\u003cp\\u003e\\u003cp\\u003e \\u003cb\\u003eNote:\\u003c/b\\u003e A higher value means a higher proportion of all queries, not a higher absolute query count. So a tiny country where 80% of the queries are for \\"bananas\\" will get twice the score of a giant country where only 40% of the queries are for \\"bananas\\".","url":"https://support.google.com/trends/answer/4355212"},"color":"PALETTE_COLOR_3","index":2,"bullet":"Apple","token":"APP6_UEAAAAAWbDDbNy0ioc1H3cN-yKAe9w4qU4qljlZ","id":"GEO_MAP_2","type":"fe_geo_chart_explore","title":"Interest by subregion","template":"fe","embedTemplate":"fe_embed","version":"1","isLong":false,"isCurated":false},{"request":{"restriction":{"geo":{"country":"US"},"time":"2017-08-06 2017-09-05","complexKeywordsRestriction":{"keyword":[{"type":"BROAD","value":"Apple"}]}},"keywordType":"QUERY","metric":["TOP","RISING"],"trendinessSettings":{"compareTime":"2017-07-06 2017-08-05"},"requestOptions":{"property":"","backend":"IZG","category":0},"language":"en"},"helpDialog":{"title":"Related queries","content":"Users searching for your term also searched for these queries. You can sort by the following metrics: \\u003cp\\u003e* \\u003cb\\u003eTop\\u003c/b\\u003e - The most popular search queries. Scoring is on a relative scale where a value of 100 is the most commonly searched query, 50 is a query searched half as often, and a value of 0 is a query searched for less than 1% as often as the most popular query. \\u003cp\\u003e* \\u003cb\\u003eRising\\u003c/b\\u003e - Queries with the biggest increase in search frequency since the last time period. Results marked \\"Breakout\\" had a tremendous increase, probably because these queries are new and had few (if any) prior searches.","url":"https://support.google.com/trends/answer/4355000"},"color":"PALETTE_COLOR_3","keywordName":"Apple","token":"APP6_UEAAAAAWbDDbJeiZ14aIjNtCowwwvSHLz-6AwWC","id":"RELATED_QUERIES_2","type":"fe_related_searches","title":"Related queries","template":"fe","embedTemplate":"fe_embed","version":"1","isLong":false,"isCurated":false}],"keywords":[{"keyword":"Dell","name":"Dell","type":"Search term"},{"keyword":"Lenovo","name":"Lenovo","type":"Search term"},{"keyword":"Apple","name":"Apple","type":"Search term"}],"timeRanges":["8/6/17 - 9/5/17","8/6/17 - 9/5/17","8/6/17 - 9/5/17"],"examples":[],"shareText":"Explore search interest for Dell, Lenovo, Apple by time, location and popularity on Google Trends"}' }

rmshkmr commented 7 years ago

@nicholaai i'm using 4.1.0 version. Still showing the error.

nicholaai commented 7 years ago

Make sure you're using exactly 4.1.0. If you have a ~ or ^ in your package.json, you may not be. Check that file and make the change then do npm install again. You can also check using npm list google-trends-api

pat310 commented 7 years ago

@nicholaai Thanks for reporting this. I think I have corrected it in PR #78 - probably going to add some tests to prevent this from happening again in the future

pat310 commented 7 years ago

@nicholaai Fixed in verison 4.2.2. Let me know if it's still not working for you!