Curl call to ColdFusion - Instagram

2019-08-01 07:43发布

问题:

I'm not experienced with cURL at all, but from what I can gather, it's equivalent to cfhttp.

I want to work with the Instagram API and authenticate a user. Their example uses cURL.

curl \-F 'client_id=CLIENT-ID' \
    -F 'client_secret=CLIENT-SECRET' \
    -F 'grant_type=authorization_code' \
    -F 'redirect_uri=YOUR-REDIRECT-URI' \
    -F 'code=CODE' \https://api.instagram.com/oauth/access_token

Would I be correct in thinking the CF version would be:

<cfhttp url="https://api.instagram.com/oauth/access_token" method="post" resolveurl="true">
    <cfhttpparam type="formField" name="client_id" value="CLIENT-ID" />
    <cfhttpparam type="formField" name="client_secret" value="CLIENT-SECRET" />
    <cfhttpparam type="formField" name="grant_type" value="authorization_code" />
    <cfhttpparam type="formField" name="redirect_uri" value="YOUR-REDIRECT-URI" />
    <cfhttpparam type="formField" name="code" value="code" />
</cfhttp>

I'm not able to try this yet as I won't be at my development machine until a lot later, so I'm just digging around right now looking at possibilities and making pseudo-code (not tested!).

Anyone with specific experience with the Instagram API and ColdFusion who could shed some insight would be greatly appreciated.

I'm using Railo.

回答1:

According to how to use cURL the -F option is form data.

http://curl.haxx.se/docs/manpage.html

So you're going to want to send form data, not url data in your cfhttpparam tags.

<cfhttp url="https://api.instagram.com/oauth/access_token" method="post" resolveurl="true">
    <cfhttpparam type="formField" name="client_id" value="CLIENT-ID" />
    <cfhttpparam type="formField" name="client_secret" value="CLIENT-SECRET" />
    <cfhttpparam type="formField" name="grant_type" value="authorization_code" />
    <cfhttpparam type="formField" name="redirect_uri" value="YOUR-REDIRECT-URI" />
    <cfhttpparam type="formField" name="code" value="code" />
</cfhttp>

I don't know anything about the Instagram API and only what I read in the above link about cURL so this may not be the complete solution but it looks like you're on the right track.