Fan Page

Feb 2, 2010 at 10:20 PM
Edited Feb 2, 2010 at 10:21 PM

Hi at all and sorry for my english.

I 've this problem: I want to publish on the wall of a fan page by a specific user that i want to autenthicate by code.

I have searched on the forum but i don't understand how can obtain an inifite session.

I use this code to post on the wall:

Generics gen = new Generics();
        using (mojoEntities ctx = new mojoEntities())
        {
            News addNews = new News {
                Date = DateTime.Now,
                Title = gen.cleanString(txtTitolo.Text),
                Text = gen.cleanString(txtDescrizione.Text)
            };
            ctx.AddToNews(addNews);
            ctx.SaveChanges();
            //Inserimento in facebook
            Facebook.Session.ConnectSession connectsession = new Facebook.Session.ConnectSession(ConfigurationSettings.AppSettings["APIKey"], ConfigurationManager.AppSettings["Secret"]);
            connectsession.UserId = 1264950178;
            Facebook.Rest.Api api = new Facebook.Rest.Api(connectsession);

            //assume you have offline_access extended permission, and that you saved the non-expiring session key
            //and userid for future use, and put them in an object called user
            
            api.Session.SessionKey = "22be49c958f37872f1c1ce0f67";
            api.Session.UserId = 1264950178;

            Facebook.Rest.attachment_media_image myimage = new Facebook.Rest.attachment_media_image();
            //href is the link for the image if you click on it
            myimage.href = "http://mydomain.com";
            myimage.src = "http://mydomain.com/image.png";
            List<Facebook.Rest.attachment_media> mymedia = new List<Facebook.Rest.attachment_media>();
            mymedia.Add(myimage);

            Facebook.Rest.attachment myattachment = new Facebook.Rest.attachment();

            //name is bold heading for entry, to right of image
            myattachment.name = "Title of your post";
            //href is the link target for the 'name'
            myattachment.href = "http://mydomain.com";

            //caption is the long article text below the name
            myattachment.caption = "Here is the main message for the wall/stream post";

            //description appears under image
            myattachment.description = "Something to describe the image";

            myattachment.media = mymedia;

            IList<Facebook.Schema.action_link> myactionlinks = new List<Facebook.Schema.action_link>();
            Facebook.Schema.action_link myactionlink = new Facebook.Schema.action_link();
            myactionlink.href = "http://mydomain.com";
            myactionlink.text = "Description for hyperlink";
            myactionlinks.Add(myactionlink);
            //response = API.stream.publish("test message", null, new List<action_link>() {new action_link() { text = SName, href = strAppLink }}, "", TargetWallID);
            string test = "250941212437";
            api.Stream.Publish("Yeah", myattachment, myactionlinks, test.ToString(), 250941212437);
            //api.Stream.Publish("", myattachment, myactionlinks, "", user.UserID);

            //Fine inserimento in facebook
            Response.Redirect("conferma.aspx", false);
        }

but i obtain an error that say "Session is no longer valid".

With YouTube api i can login from code and upload a video, and I would to do something like this with facebook, ie, authenticate via code as a specified user and update my page.

Please, help me, because i'm going crazy :(

Feb 3, 2010 at 1:14 AM

Hi there,

I see this in your code:

//assume you have offline_access extended permission, and that you saved the non-expiring session key
//and userid for future use, and put them in an object called user


Would you like to let me know how we get the session key by some code? Thanks very much.
Feb 3, 2010 at 8:04 AM

Hi monkeyvu,

it's the same thing that i would to know!

I want to login from my web application and i want to update my page fan!

But i don't understand how do the autentication from my application!!

Feb 3, 2010 at 11:26 PM

I don't believe that no reason for my question.

Please help!

Feb 5, 2010 at 10:46 PM

Hi at all!

After few nights that I spend to resolve my problem, finally tonight i have solved a part.

I have used this code:

            //Inserimento in facebook
            string appId = System.Configuration.ConfigurationManager.AppSettings["APIKey"];
            string appSecret = System.Configuration.ConfigurationManager.AppSettings["Secret"];
            string sessionKey = "MYKEY";
            string sessionSecret = "MYSECRET";
            string targetId = "250941212437";
            //Facebook.Session.ConnectSession connectsession = new Facebook.Session.ConnectSession(appId, appSecret);
            Facebook.Session.DesktopSession deskSessione = new Facebook.Session.DesktopSession(appId, sessionSecret, sessionKey);
            Facebook.Rest.Api api = new Facebook.Rest.Api(deskSessione);
            api.Session.SessionKey = sessionKey;
            api.Session.SessionSecret = sessionSecret;
            api.Session.UserId = IDUSER;
            //Creazione post
            Facebook.Rest.attachment_media_image myimage = new Facebook.Rest.attachment_media_image();
            //href is the link for the image if you click on it
            myimage.href = "http://mydomain.com";
            myimage.src = "http://mydomain.com/image.png";
            List<Facebook.Rest.attachment_media> mymedia = new List<Facebook.Rest.attachment_media>();
            mymedia.Add(myimage);

            Facebook.Rest.attachment myattachment = new Facebook.Rest.attachment();

            //name is bold heading for entry, to right of image
            myattachment.name = "Title of your post";
            //href is the link target for the 'name'
            myattachment.href = "http://mydomain.com";

            //caption is the long article text below the name
            myattachment.caption = "Here is the main message for the wall/stream post";

            //description appears under image
            myattachment.description = "Something to describe the image";

            myattachment.media = mymedia;

            IList<Facebook.Schema.action_link> myactionlinks = new List<Facebook.Schema.action_link>();
            Facebook.Schema.action_link myactionlink = new Facebook.Schema.action_link();
            myactionlink.href = "http://mydomain.com";
            myactionlink.text = "Description for hyperlink";
            myactionlinks.Add(myactionlink);

            //Fine creazione post
            api.Stream.Publish("Yeah", myattachment, myactionlinks, targetId, 0);
            //Fine inserimento in facebook

This code does not return an error and the page go on, but on the wall of my fan page there isn't nothing!

Please help me!!