admin管理员组文章数量:1333442
I have a wordpress site which have a form and when is submitted I want to send the data to an external API. In order to access the external API and I need to pass a 2Oauth authorization. How I can achieve this without showing in the javascript the client_id & client_secret? I'm not restricted to use only javascript but I didn't found a wordpress way to do that.
Thanks.
I have a wordpress site which have a form and when is submitted I want to send the data to an external API. In order to access the external API and I need to pass a 2Oauth authorization. How I can achieve this without showing in the javascript the client_id & client_secret? I'm not restricted to use only javascript but I didn't found a wordpress way to do that.
Thanks.
Share Improve this question asked Jul 4, 2020 at 22:10 Matheu8741Matheu8741 1 1- You can write your own WP AJAX handler and pass you data to this handler, which in turn would pass it further via WP HTTP API using your client_id and client_secret (stored in database or directly within PHP code). Once I solved the similar problem this way. – Ivan Shatsky Commented Jul 4, 2020 at 22:33
1 Answer
Reset to default 0I'd suggest you should call the API from the server, not from the client. This should be possible when the form is submitted and as you say doing OAuth from the browser introduces a lot more issues.
This is a fair bit of work, so I'd suggest this general structure to the way you approach it:
- Figure out how to do the OAuth authentication you need and calling the remote API in plain PHP code outside of Wordpress. This is difficult enough, you don't want to try to make this work inside Wordpress first.
- Once you can do this, do the simplest possible integration with Wordpress - e.g. in a plugin with e.g. a shortcode just to test that you can make this code run from inside Wordpress ok.
- Once you've done this, figure out how to call the code when the form is submitted, e.g. by hooking in to a Wordpress action that runs when your form is submitted, or finding some other way to run code on the server when the form is submitted.
HTH, please post if you have any followup or more specific questions.
本文标签: Call external API
版权声明:本文标题:Call external API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742290867a2447768.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论