httr POST with keywordtool.io



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm struggling to get httr to work with an API that my company is currently using and for the life of me I can't work out why.



x <- c("Electronic cigarette", 
"Cloud-chasing electronic cigarette",
"Safety of electronic cigarettes",
"Electronic cigarette aerosol and liquid",
"Openvape",
"Blu eCigs",
"Regulation of electronic cigarettes",
"PAX Labs",
"Construction of electronic cigarettes",
"Vape shop",
"Hon Lik",
"Dragonite International Limited",
"Positions of medical organizations on electronic cigarettes",
"Evolv",
"List of vaping bans in the United States",
"VMR Products",
"List of electronic cigarette brands",
"Electronic cigarettes in Australia",
"LOGIC electronic cigarette",
"VUSE electronic cigarette",
"NJOY",
"R. J. Reynolds Vapor Company",
"MarkTen",
"Vista Vapors",
"Riccardo Polosa",
"Ten Motives",
)

vars <- list(
keyword = as.character(x),
apikey = "apikeyhere",
metrics_location = "2826",
metrics_language = "en",
metrics_network = "googlesearchnetwork",
metrics_currency = "USD",
output = "json"
)


res <- POST("https://api.keywordtool.io/v2/search/volume/google"
, body = vars
, encode = "json", verbose())


when I do this for different metrics locations (e.g., 2826 is the UK), it just returns the data for the US which is the default. Is seems to be reading the data in the keyword portion of the list, but then ignoring the rest. The documentation for the API can be found here (unfortunatley the API is paid): https://keywordtool.io/api/documentation#examples



I'm able to get different results for the US and the UK when I format as a php script and run via the terminal, I just don't seem to be able to get it to work with httr. Ideas would be welcome.



edit:



two of the parameters needed to have their values in a list, even if for just one item. poor comprehension on my part.










share|improve this question
























  • If you can get it to work with php, try posting to a site like requestb.in where you can see what's actually being sent to the server. Then compare that to what you get when you use httr to do the same. There is likely some difference in the requests you are sending.

    – MrFlick
    Feb 6 '18 at 19:12











  • thanks @MrFlick, good suggestion. I've uploaded the output to imgur: imgur.com/a/T6rkc the output nearest the top is a php script, the lower is httr. The headers are different, but not in a way that seems relevant to the differing output, as far as I can tell.

    – user1200
    Feb 7 '18 at 8:23


















0















I'm struggling to get httr to work with an API that my company is currently using and for the life of me I can't work out why.



x <- c("Electronic cigarette", 
"Cloud-chasing electronic cigarette",
"Safety of electronic cigarettes",
"Electronic cigarette aerosol and liquid",
"Openvape",
"Blu eCigs",
"Regulation of electronic cigarettes",
"PAX Labs",
"Construction of electronic cigarettes",
"Vape shop",
"Hon Lik",
"Dragonite International Limited",
"Positions of medical organizations on electronic cigarettes",
"Evolv",
"List of vaping bans in the United States",
"VMR Products",
"List of electronic cigarette brands",
"Electronic cigarettes in Australia",
"LOGIC electronic cigarette",
"VUSE electronic cigarette",
"NJOY",
"R. J. Reynolds Vapor Company",
"MarkTen",
"Vista Vapors",
"Riccardo Polosa",
"Ten Motives",
)

vars <- list(
keyword = as.character(x),
apikey = "apikeyhere",
metrics_location = "2826",
metrics_language = "en",
metrics_network = "googlesearchnetwork",
metrics_currency = "USD",
output = "json"
)


res <- POST("https://api.keywordtool.io/v2/search/volume/google"
, body = vars
, encode = "json", verbose())


when I do this for different metrics locations (e.g., 2826 is the UK), it just returns the data for the US which is the default. Is seems to be reading the data in the keyword portion of the list, but then ignoring the rest. The documentation for the API can be found here (unfortunatley the API is paid): https://keywordtool.io/api/documentation#examples



I'm able to get different results for the US and the UK when I format as a php script and run via the terminal, I just don't seem to be able to get it to work with httr. Ideas would be welcome.



edit:



two of the parameters needed to have their values in a list, even if for just one item. poor comprehension on my part.










share|improve this question
























  • If you can get it to work with php, try posting to a site like requestb.in where you can see what's actually being sent to the server. Then compare that to what you get when you use httr to do the same. There is likely some difference in the requests you are sending.

    – MrFlick
    Feb 6 '18 at 19:12











  • thanks @MrFlick, good suggestion. I've uploaded the output to imgur: imgur.com/a/T6rkc the output nearest the top is a php script, the lower is httr. The headers are different, but not in a way that seems relevant to the differing output, as far as I can tell.

    – user1200
    Feb 7 '18 at 8:23














0












0








0








I'm struggling to get httr to work with an API that my company is currently using and for the life of me I can't work out why.



x <- c("Electronic cigarette", 
"Cloud-chasing electronic cigarette",
"Safety of electronic cigarettes",
"Electronic cigarette aerosol and liquid",
"Openvape",
"Blu eCigs",
"Regulation of electronic cigarettes",
"PAX Labs",
"Construction of electronic cigarettes",
"Vape shop",
"Hon Lik",
"Dragonite International Limited",
"Positions of medical organizations on electronic cigarettes",
"Evolv",
"List of vaping bans in the United States",
"VMR Products",
"List of electronic cigarette brands",
"Electronic cigarettes in Australia",
"LOGIC electronic cigarette",
"VUSE electronic cigarette",
"NJOY",
"R. J. Reynolds Vapor Company",
"MarkTen",
"Vista Vapors",
"Riccardo Polosa",
"Ten Motives",
)

vars <- list(
keyword = as.character(x),
apikey = "apikeyhere",
metrics_location = "2826",
metrics_language = "en",
metrics_network = "googlesearchnetwork",
metrics_currency = "USD",
output = "json"
)


res <- POST("https://api.keywordtool.io/v2/search/volume/google"
, body = vars
, encode = "json", verbose())


when I do this for different metrics locations (e.g., 2826 is the UK), it just returns the data for the US which is the default. Is seems to be reading the data in the keyword portion of the list, but then ignoring the rest. The documentation for the API can be found here (unfortunatley the API is paid): https://keywordtool.io/api/documentation#examples



I'm able to get different results for the US and the UK when I format as a php script and run via the terminal, I just don't seem to be able to get it to work with httr. Ideas would be welcome.



edit:



two of the parameters needed to have their values in a list, even if for just one item. poor comprehension on my part.










share|improve this question
















I'm struggling to get httr to work with an API that my company is currently using and for the life of me I can't work out why.



x <- c("Electronic cigarette", 
"Cloud-chasing electronic cigarette",
"Safety of electronic cigarettes",
"Electronic cigarette aerosol and liquid",
"Openvape",
"Blu eCigs",
"Regulation of electronic cigarettes",
"PAX Labs",
"Construction of electronic cigarettes",
"Vape shop",
"Hon Lik",
"Dragonite International Limited",
"Positions of medical organizations on electronic cigarettes",
"Evolv",
"List of vaping bans in the United States",
"VMR Products",
"List of electronic cigarette brands",
"Electronic cigarettes in Australia",
"LOGIC electronic cigarette",
"VUSE electronic cigarette",
"NJOY",
"R. J. Reynolds Vapor Company",
"MarkTen",
"Vista Vapors",
"Riccardo Polosa",
"Ten Motives",
)

vars <- list(
keyword = as.character(x),
apikey = "apikeyhere",
metrics_location = "2826",
metrics_language = "en",
metrics_network = "googlesearchnetwork",
metrics_currency = "USD",
output = "json"
)


res <- POST("https://api.keywordtool.io/v2/search/volume/google"
, body = vars
, encode = "json", verbose())


when I do this for different metrics locations (e.g., 2826 is the UK), it just returns the data for the US which is the default. Is seems to be reading the data in the keyword portion of the list, but then ignoring the rest. The documentation for the API can be found here (unfortunatley the API is paid): https://keywordtool.io/api/documentation#examples



I'm able to get different results for the US and the UK when I format as a php script and run via the terminal, I just don't seem to be able to get it to work with httr. Ideas would be welcome.



edit:



two of the parameters needed to have their values in a list, even if for just one item. poor comprehension on my part.







r post httr






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 7 '18 at 13:23







user1200

















asked Feb 6 '18 at 18:30









user1200user1200

104




104












  • If you can get it to work with php, try posting to a site like requestb.in where you can see what's actually being sent to the server. Then compare that to what you get when you use httr to do the same. There is likely some difference in the requests you are sending.

    – MrFlick
    Feb 6 '18 at 19:12











  • thanks @MrFlick, good suggestion. I've uploaded the output to imgur: imgur.com/a/T6rkc the output nearest the top is a php script, the lower is httr. The headers are different, but not in a way that seems relevant to the differing output, as far as I can tell.

    – user1200
    Feb 7 '18 at 8:23


















  • If you can get it to work with php, try posting to a site like requestb.in where you can see what's actually being sent to the server. Then compare that to what you get when you use httr to do the same. There is likely some difference in the requests you are sending.

    – MrFlick
    Feb 6 '18 at 19:12











  • thanks @MrFlick, good suggestion. I've uploaded the output to imgur: imgur.com/a/T6rkc the output nearest the top is a php script, the lower is httr. The headers are different, but not in a way that seems relevant to the differing output, as far as I can tell.

    – user1200
    Feb 7 '18 at 8:23

















If you can get it to work with php, try posting to a site like requestb.in where you can see what's actually being sent to the server. Then compare that to what you get when you use httr to do the same. There is likely some difference in the requests you are sending.

– MrFlick
Feb 6 '18 at 19:12





If you can get it to work with php, try posting to a site like requestb.in where you can see what's actually being sent to the server. Then compare that to what you get when you use httr to do the same. There is likely some difference in the requests you are sending.

– MrFlick
Feb 6 '18 at 19:12













thanks @MrFlick, good suggestion. I've uploaded the output to imgur: imgur.com/a/T6rkc the output nearest the top is a php script, the lower is httr. The headers are different, but not in a way that seems relevant to the differing output, as far as I can tell.

– user1200
Feb 7 '18 at 8:23






thanks @MrFlick, good suggestion. I've uploaded the output to imgur: imgur.com/a/T6rkc the output nearest the top is a php script, the lower is httr. The headers are different, but not in a way that seems relevant to the differing output, as far as I can tell.

– user1200
Feb 7 '18 at 8:23













1 Answer
1






active

oldest

votes


















-1














There seems to be a problem with the params , the metrics_location seems to be overwritten by the default GLOBAL/ENGLISH or its not loaded .
First check https://keywordtool.io/api .
Then simply add: "https://api.keywordtool.io/v2/search/volume/google?metrics_location=[NUMBERS] to the url . It worked for me .






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48649657%2fhttr-post-with-keywordtool-io%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    There seems to be a problem with the params , the metrics_location seems to be overwritten by the default GLOBAL/ENGLISH or its not loaded .
    First check https://keywordtool.io/api .
    Then simply add: "https://api.keywordtool.io/v2/search/volume/google?metrics_location=[NUMBERS] to the url . It worked for me .






    share|improve this answer



























      -1














      There seems to be a problem with the params , the metrics_location seems to be overwritten by the default GLOBAL/ENGLISH or its not loaded .
      First check https://keywordtool.io/api .
      Then simply add: "https://api.keywordtool.io/v2/search/volume/google?metrics_location=[NUMBERS] to the url . It worked for me .






      share|improve this answer

























        -1












        -1








        -1







        There seems to be a problem with the params , the metrics_location seems to be overwritten by the default GLOBAL/ENGLISH or its not loaded .
        First check https://keywordtool.io/api .
        Then simply add: "https://api.keywordtool.io/v2/search/volume/google?metrics_location=[NUMBERS] to the url . It worked for me .






        share|improve this answer













        There seems to be a problem with the params , the metrics_location seems to be overwritten by the default GLOBAL/ENGLISH or its not loaded .
        First check https://keywordtool.io/api .
        Then simply add: "https://api.keywordtool.io/v2/search/volume/google?metrics_location=[NUMBERS] to the url . It worked for me .







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 13:45









        MariusMarius

        1




        1





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48649657%2fhttr-post-with-keywordtool-io%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党