2

I'm absolutely new to programming and just managed to learn the basics of ActionScript 3. Now, I would like to learn how to post on my Friends' Walls via the as3 SDK using the UI class (taken from a nice Tutorial):

This is how I post on my own Wall:

protected function newsFeed ():void
        {
            
            // define your caption text
            var theCaption:String = "CaptionText";
            
            // define the descrition text
            var theDescription:String = "Text for game Achievement";
            
            // We need to follow the FB docs to tell it what sort of input we are sending to FB
            // We are trying to set the 'feed'
            var methodInput:String = 'feed';
            
            var thePicture:String = "mylink/picture.png";
            var theLink:String = "mylink";
            var theName:String = "Name of FB Status Setter";
            
            // Create an object that we'll call 'data' and fill it with the actual data we're sending to Facebook
            var data:Object = {
                caption:theCaption, 
                description:theDescription, 
                picture:thePicture, 
                name:theName, 
                link:theLink
            };
          Facebook.ui(methodInput, data, onUICallback);
         }

protected function onUICallback(result:Object):void
    {
    // do something
    }

This works perfectly fine. I know that I have to integrate the parameter "to" somewhere. But I don't know where and how. Sorry I'm very very new to this. This is from Facebook Docs

Properties

from: The ID or username of the user posting the message. If this is unspecified, it defaults to the current user. If specified, it must be the ID of the user or of a page >that the user administers.

to: The ID or username of the profile that this story will be published to. If this >is unspecified, it defaults to the the value of from.

Hopefully someone can help me out.

Best Regards, Amir P.S.: Is there a way to post only one friend's wall and another way to post on several friends' walls?

Community
  • 1
  • 1
Amir Rahbaran
  • 2,380
  • 2
  • 21
  • 28
  • I've seen a lot of very similar questions lately. Is this a class assignment? – Mar Feb 29 '12 at 17:06
  • hello mouseas, no, this is not a class assignment. where did you dinf similar questions, maybe I should take a look? i did a huge google research, couldn't find anything (as3-sdk FRIEND'S wall) – Amir Rahbaran Mar 01 '12 at 21:40
  • I've seen a lot of facebook questions on Stack Overflow the last few weeks. I remember at least one was specifically about posting to a FB Wall. I didn't read it, though, since I didn't have a clue to the answer. Just noticing a trend. – Mar Mar 01 '12 at 21:48

1 Answers1

4

I believe you want to use Facebook.api() rather than 'ui'. According to the documentation for the AS3 FB API, 'ui' just opens the share dialog. If you want to create a post on a friends wall, then you'll want to use 'api'.

I haven't tested this in Flash, but I think you can set the method as /PROFILE_ID/feed ... of course replacing "PROFILE_ID" with the FB uid of the friend. Then, include the arguments; message, picture, link, name, caption, description and source in your data object.

So your code would look something like:

var method:String = "/friend_id/feed";
var data:Object = {};

data.message = "Your message";
data.picture = "http://www.google.com/kittens.jpg";
data.link = "http://www.mysite.com/link";
data.caption = "Your caption";
data.description = "Your description";
data.source = "http://www.mysite.com/video.swf";//(optional) source is a video or Flash SWF

Facebook.api(method, yourCallback, data, "POST");

function yourCallback(result:Object, fail:Object):void {
    if (result) {
        trace(result)
    } else if (fail) {
        trace(fail);
    }
}

If you have multiple friends, you could probably just put the uid's in an array and loop through the method above. The AS3 API has a batch request method that I haven't tried, but you can check out the Documentation.

Facebook has some pretty helpful tools that are somewhat hidden.
Checkout their Debugger and their Graph API Explorer

Hope that's helpful.

Corey
  • 5,818
  • 2
  • 24
  • 37
  • Hello Corey, Thank you for your answer and sorry for taking my time to answer. P.S.: Just to let you know, I can't mark your answer as helpful, because I don't have the required 15 reputation points. – Amir Rahbaran Mar 01 '12 at 21:51
  • Hello Corey, Sorry for the upper post, I accidentally pressed ENTER, I it took me more than five minute to edit (which is prohibited). Anyway, I tried your code, but it didn't work. Regarding using the ui class. I don't know why but my above code works for sharing. You can check out my "experimenting app". It really ugly, just for learning purposes. If you use it, please don't forget not to make your posts private: https://apps.facebook.com/flex_tutorial The "api-feed-button" entails your code. If you push the ""Post-on-Wall-Button", you'll the that the above code works. Cheers, Amir – Amir Rahbaran Mar 01 '12 at 21:58
  • I get an IOError when clicking the api-feed button. The url shows: https://graph.facebook.com/friend_id/feed. You need to replace "friend_id" with the actual uid of the friend with whom you wish to share. – Corey Mar 02 '12 at 16:58
  • Thank you very much for all your patience. Now it works. However, I still haven't fully grasped it. The player should choose on which wall he wants to post it. So, just putting in the UID can't be the solution, I guess. – Amir Rahbaran Mar 04 '12 at 16:55
  • No, unfortunately not. You'll also need to create a friend selector that the user can use to select their friend(s). Once they make their selection, you'll just store the selected IDs and use them in the above method. – Corey Mar 05 '12 at 15:28
  • Ok, I think you have me an idea, how to do it. Thank you very much for time. Highly appreciated! – Amir Rahbaran Mar 07 '12 at 20:10
  • Remember - you need the extended permission 'publish_stream' from Facebook.login – fideldonson Jul 23 '12 at 20:30