• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I post to facebook's graph api with cfhttp?

Participant ,
Apr 09, 2012 Apr 09, 2012

Copy link to clipboard

Copied

How do I post to Facebook Graph API with Coldfusion?

The following works fine up until my cfhttp post.

I want to post with cfhttp to a user's wall/timeline.

<!--- This is the page that you call and also use as the redirect_uri... facebook returns code and state in the URL --->

<cfparam name="URL.code" default="" type="string">

<cfparam name="URL.state" default="" type="string">

<cfif #URL.code# EQ "">

    <cfparam name="URL.error_reason" default="" type="string">

    <cfparam name="URL.error" default="" type="string">

    <cfparam name="URL.error_description" default="" type="string">

    <cfmail charset="utf-8" type="html" server="mail.mysite.com" from="messages@mysite.com" to="messages@mysite.com" subject="Facebook Authentication Denial">

    #SESSION.my_profile_id#: #SESSION.my_profile_username#

    #URL.error_reason#<br/>

    #URL.error#<br/>

    #URL.error_description#<br/>

    </cfmail>

    <cfabort>

<cfelse>

    <cfhttp

    method="get"

    url="https://graph.facebook.com/oauth/access_token?client_id=myappid&redirect_uri=http://www.mysite.com/d..."

    result="my_fb_user_token"/>

    <cfif #my_fb_user_token.filecontent# CONTAINS "access_token=">

        <cfset new_token = ReplaceNoCase(#my_fb_user_token.filecontent#,"&expires","|","all")>

        <cfset new_token = REReplaceNoCase(#new_token#,"\|.*$","")>

        <cfquery name="fb_confusion" datasource="#dsn#" maxrows="1">

        SELECT facebook_id

        FROM my_profile

        WHERE my_profile_id = '#SESSION.my_profile_id#'

        </cfquery>

        <cfoutput>#new_token#</cfoutput>

        <hr/>

        <cfhttp

        method="get"

        url="https://graph.facebook.com/me?#new_token#"

        result="my_fb_user"/>

        <cfoutput>https://graph.facebook.com/#fb_confusion.facebook_id#/feed?#new_token#</cfoutput>

        <hr/>

        <cfoutput>

        <cfhttp url="https://graph.facebook.com/me/mysite:add?group=http://www.mysite.com/dbf/test_group.cfm&#new_token#"

        result="fb_publish"

        method="post"

        multipart="yes">

            <cfhttpparam name="appID" value="myappid" encoded="no" type="url">

            <cfhttpparam name="access_token" value="#my_fb_user_token.filecontent#" encoded="no" type="url">

            <cfhttpparam name="message" value="Test" encoded="no" type="url">

            <cfhttpparam name="link" value="http://www.mysite.com" encoded="no" type="url">

            <cfhttpparam name="name" value="Test" encoded="no" type="url">

            <cfhttpparam name="caption" value="Testing fb api" encoded="no" type="url">

            <cfhttpparam name="description" value="Testing to see if this posts" encoded="no" type="url">

        </cfhttp>

        </cfoutput>

        <cfdump var="#fb_publish.filecontent#">

    </cfif>

</cfif>

The message returned from the fb_publish dump is:

{"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}

TOPICS
Advanced techniques

Views

2.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Apr 10, 2012 Apr 10, 2012

Ok thank you Ray C for helping out with this.  Couple things... first, the URL being called by the http post needs to synch up with what facebook requires.

https://graph.facebook.com/me/[YOUR_APP_NAMESPACE]:cook?recipe=OBJECT_URL&access_token=ACCESS_TOKEN

Next, all the type="url" in the cfhttp form params needed to be changed to formfield.

Now it works.

Thanks!

Votes

Translate

Translate
Participant ,
Apr 10, 2012 Apr 10, 2012

Copy link to clipboard

Copied

LATEST

Ok thank you Ray C for helping out with this.  Couple things... first, the URL being called by the http post needs to synch up with what facebook requires.

https://graph.facebook.com/me/[YOUR_APP_NAMESPACE]:cook?recipe=OBJECT_URL&access_token=ACCESS_TOKEN

Next, all the type="url" in the cfhttp form params needed to be changed to formfield.

Now it works.

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation