2012-04-10 1 views
2

페이스 북의 사이트에서 자습서/설명서를 읽고 coldfusion을 사용하여 사용자의 벽/타임 라인에 게시하는 것보다 한 걸음 앞서 있습니다. cfhttp를 사용하여 자동으로 게시하는 마지막 단계가 있습니다. 나는 그것을 작동시킬 수 없다. 메시지가 fb_publish 덤프에서 반환cfhttp를 사용하여 페이스 북의 그래프 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> 

은 다음과 같습니다

{ "오류": { "메시지": "잘못된 OAuth 액세스 토큰입니다.", "유형": "OAuthException", "코드" (190)}}

+1

액세스 토큰이 유효합니까? 적절한 oAuth 프로세스를 통해 토큰을 받았습니까? – Jason

+0

예. 토큰이 유효합니다. 위의 코드에서 결과를 복사 한 다음 페이스 북의 그래프 디버거에 붙여 넣으면 제대로 작동합니다. cfhttp method = "post"로 시작하는 문제 –

+0

8 시간까지 대답 할 수 없습니다 ... ㅋㅋㅋ. 먼저 cfhttp 게시물의 URL을 페이스 북의 게시물 URL로 변경해야합니다 (https://graph.facebook.com/me/[YOUR_APP_NAMESPACE]:cook?recipe=OBJECT_URL&access_token=ACCESS_TOKEN ). 다음으로, 내 매개 변수는 type = "url"에서 type = "formfield"로 변경해야했습니다. 그게 전부입니다. 이제 작동합니다. –

답변