Posting Feeds to Facebook using Graph API - Server side - facebook

I'm trying to post feeds to the personal facebook wall and the fan page wall from my site for a logged in user.
<cfhttp url="https://graph.facebook.com/me/feed" method="post">
<cfhttpparam name="access_token" value="#variables.accessToken#" type="formfield">
<cfhttpparam name="message" value="#arguments.message#" type="formfield">
<cfhttpparam name="link" value="#arguments.link#" type="formfield">
<cfhttpparam name="name" value="#arguments.name#" type="formfield">
<cfhttpparam name="caption" value="#arguments.caption#" type="formfield">
<cfhttpparam name="description" value="#arguments.description#" type="formfield">
<cfhttpparam name="picture" value="#arguments.picturePath#" type="formfield">
</cfhttp>
This is as per the code from developers.facebook.com and a sample from http://net.tutsplus.com/tutorials/php/wrangling-with-the-facebook-graph-api/
This is just a sample of what I think the parameters mean:
But when it posts to the wall, the following happens:
The message, picture, name, caption and description appear properly
But the link does not, the picture points to itself and the link on the name points to the picture.
After referring to numerous posts, I thought I'd post this.
Please help.

You should give the protocol as well.
So try this:
http://www.traffikworks.com/community.html
(I put the www, becuase you redirect the browser anyway with 301)

Related

Facebook Graph API: Update Page Post Message

I'm trying to use the facebook graph api to update the message on a previous post. I have the original post id and a valid never ending user access token. I am getting a "success" message back, but the post message is NOT getting updated.
<CFHTTP METHOD="POST" URL="https://graph.facebook.com/v3.2/#qPost.PostID#?message=#URLEncodedFormat(Message)#&access_token=#AccessToken#" THROWONERROR="YES">
<cfhttpparam type="header" name="Accept-Encoding" value="*" />
<cfhttpparam type="header" name="TE" value="deflate;q=0" />
</CFHTTP>
Success Message:
I'm going off the facebook graph details here (i know it says publish_actions permission has been removed), but certainly there has to be a way to update a page post via the graph api.
https://developers.facebook.com/docs/graph-api/reference/v3.2/post#updating
Also when I say I'm trying to update the message, basically the text that is written in the post (see image)
I got this figured out, i was not using the full postid in my request. When the original post was created it sends back a post id, which is a combination of the pageid and the postid (with an underscore in between), it looks like this below, with the first part being the pageid and the one after the underscore being the postid, I was only putting the 2nd part as the postid:
334797943936653_2003899366299670
It's funny that i would still get a "success" even though I had an invalid postid.
The documentation example states
POST /v3.2/post-id HTTP/1.1
Host: graph.facebook.com
message=This+is+a+test+message
So message is part of the POST body. But your code sends the message as part of the query string. Solution: Move message and access_token to the body.
<cfhttp method="POST" url="https://graph.facebook.com/v3.2/#qPost.PostID#" throwOnError="true">
<cfhttpparam type="header" name="Accept-Encoding" value="*" />
<cfhttpparam type="header" name="TE" value="deflate;q=0" />
<cfhttpparam type="formfield" name="message" value="#Message#" />
<cfhttpparam type="formfield" name="access_token" value="#AccessToken#" />
</cfhttp>
Encoding is done by cfhttpparam automatically, so keep the readable/desired text in the message variable.

callback URL after succesfull Video post trough Facebook API graph

I'm starting to get my Facebook integration working on my own app but I'm still strugling with one part:
create a callback URL of redirect URL after a successful video post on my facebook wall trough:
<form enctype="multipart/form-data" action="https://graph-video.facebook.com/v2.9/me/videos?source={{video_source}}&access_token={{access_token}}="POST">
<input name="file" type="file" value="">
<input type="submit" value="Upload" />
</form>
Does anyone know how to do this. So after a successfull upload redirect to a page in my app.
Thanks for helping me out.

Unable to upload image to a Coldfusion REST API Service

I am using CF10 REST API Service and trying to upload an a profile picture for a user.
The service method tries to save this image to a destination:
<cfcomponent rest="true"
restpath="/users">
<cffunction name="saveProfilePicture"
access="remote"
httpmethod="POST"
restpath="{userid}/profilePicture"
returntype="any">
<cfargument name="uploadedImage" required="true"/>
<cfargument name="userid" required="true" restargsource="Path"/>
<cffile
action="upload"
destination="#upload_path#"
fileField="uploadedImage"
result="profilePicture"
accept="image/jpg"
/>
</cffunction>
</cfcomponent>
I am trying to call this service as follows:
<form method="POST" enctype="multipart/form-data" action="#path#/users/#userid#/profilePicture">
<input type="file" name="uploadedImage"/>
<input type="submit" name="btn_submit_profilePicture" id="btn_submit_profilePicture"
value="Submit"/>
</form>
After I make this call I get an error message "Unsupported Media Type".
I get the same issue if I use cfhttp:
<cfhttp url="#path#/users/#userid#/profilePicture"
result="restResult" method="POST" multipart="true">
<cfhttpparam file="someimage.jpg" mimetype="image/jpg"
name="uploadedImage" type="file"/>
</cfhttp>
I have tried to search around but couldn't find a solution that works.
I can't use a framework as of now as most of the API is already implemented over CF REST API so guess I am stuck with it.
Any help would be greatly appreciated. Thanks.
Change your code like the following and test it.
<cfcomponent rest="true"
restpath="/users">
<cffunction name="saveProfilePicture"
access="remote"
httpmethod="POST"
restpath="{userid}/profilePicture"
returntype="any">
<cfargument name="uploadedImage" restargsource="form"/>
<cfargument name="userid" restargsource="Path"/>
<cffile
action="upload"
destination="#upload_path#"
result="arguments.uploadedImage"
accept="image/jpg,image/jpeg"
/>
</cffunction>
</cfcomponent>

Facebook page admin did not have publish actions permission

I want to do a facebook post from my coldfusion application to a test page. I have created a test page and I am the admin of that page. Now I got the API key and Page ID with the given details. The issue is when I post the request to facebook using
<cfhttp url="https://graph.facebook.com/v2.2/#MyPageID#/feed" result="access" >
<cfhttpparam type="formfield" name="access_token" value="#MyAccessToken#" />
<cfhttpparam type="formfield" name="message" value="#MyMessage#" />
</cfhttp>
I am getting all the posts from my page and the message is not posted. Can anyone help? Please let me know if you need any more help.
Oh. It is just a simple mistake and it made me to hang for hours. After wasting much hours, I have found that the HTTP call method must be post.
<cfhttp url="https://graph.facebook.com/v2.2/#MyPageID#/feed" result="access" method="false">
<cfhttpparam type="formfield" name="access_token" value="#MyAccessToken#" />
<cfhttpparam type="formfield" name="message" value="#MyMessage#" />
</cfhttp>
So the final lesson is, when the method is get, it reads the posts and when it is post, it adds a new post.

cfhttp multipart & facebook

I'm playing with the facebook graph api, and was attempting to send an image to my wall. According to facebook, you just send the image, your access key & a caption... see below my code:
<cfoutput>
<cfif fileexists("D:\myPath\images\menubar.jpg")>
<cfhttp method="post" url="https://graph.facebook.com/me/photos" multipart="yes">
<cfhttpparam type="formfield" name="access_token" value="myAccessToken">
<cfhttpparam type="file" name="source" file="D:\myPath\images\menubar.jpg">
<cfhttpparam type="formfield" name="message" value="this is a test picture.">
</cfhttp>
<cfdump var="#cfhttp#">
</cfif>
</cfoutput>
When I run this, I get a 400 bad request error ("OauthException an unknown error occurred" returns from facebook). Does anyone know what I'm doing wrong? Thanks!
can you check your access token format?
usually parameters set as access_token=somedata&expires=sometimestamp
At the statement you mentioned above, you have to pass just access token literally. I make it bold here. access_token=somedata&expires=sometimestamp
I've been trying to solve the same problem nearly for 3 hours. :) and finally did!
I've run into issues using https when the secure certificate hasn't been imported into the Java/ColdFusion keystore. More info on how to achieve that here:
http://kb2.adobe.com/cps/400/kb400977.html
Hope that helps!