2
我已经关注了Facebook网站上的教程/文档,并且使用coldfusion发布到用户的墙/时间线上一步。我有最后一步,用cfhttp自动发布。我无法让它工作。如何使用cfhttp自动发布到Facebook的图形API?
<!--- 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="[email protected]" to="[email protected]" 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/dbf/_my-controller/fb_user_code.cfm&client_secret=216792f1a1ddbb568c57624a988028dc&code=#Trim(URL.code)#"
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>
该消息从fb_publish转储返回是:
{ “错误”:{ “消息”: “无效OAuth访问令牌。”, “类型”: “OAuthException”, “代码”: 190}}
您的访问令牌有效吗?你是否通过正确的oAuth流程获得了令牌? – Jason 2012-04-10 11:37:47
是的。该令牌是有效的。我在上面的代码中输出它,当它返回时复制它,并将其粘贴到Facebook的图形调试器,它工作得很好。该问题开始于cfhttp method =“post” – 2012-04-10 12:44:44
直到8小时后我才能回答......等等。首先,cfhttp文章中的URL需要更改为教程中的facebook作为其发布URL的地址:https://graph.facebook.com/me/[YOUR_APP_NAMESPACE]:cook?recipe=OBJECT_URL&access_token=ACCESS_TOKEN 接下来,我需要将参数从type =“url”更改为type =“formfield”。 就是这样。现在起作用了。 – 2012-04-10 17:45:11