below code work this with no problem
<form name="statusUpdate" action="" method="">
<textarea name="status" id="status" rows="4" cols="50"></textarea>

<input type="button" onclick="updateStatusViaJavascriptAPICalling(); return false;" value="Update Status via Facebook Javascript Library" />
</form>

}
            function updateStatusViaJavascriptAPICalling(){
                var status  =   document.getElementById('status').value;
                    FB.api('/me/feed', 'post', { message: status }, function(response) {
                        if (!response || response.error) {
                             alert('Error occured');
                        } else {
                             alert('Status updated Successfully');
                        }
                   });
            }

i would like to change no text area and onlad with var changed,is it possible?
<body onLoad="updateStatusViaJavascriptAPICalling();" />

}
            function updateStatusViaJavascriptAPICalling(){
              
  var attachment = { 'name': 'i\'m bursting with joy', 'href': ' <A href="http://bit.ly/187gO1'" rel=nofollow>http://bit.ly/187gO1'</A>, 'caption': '{*actor*} rated the lolcat 5 stars', 'description': 'a funny looking cat', 'properties': { 'category': { 'text': 'humor', 'href': '<A href="http://bit.ly/KYbaN'" rel=nofollow>http://bit.ly/KYbaN'</A>}, 'ratings': '5 stars' }, 'media': [{ 'type': 'image', 'src': '<A href="http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg'" rel=nofollow>http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg'</A>, 'href': '<A href="http://bit.ly/187gO1'" rel=nofollow>http://bit.ly/187gO1'</A>}] };   

 FB.api('/me/feed', 'post', { message: body, attachment: attachment}, function(response) 
                        if (!response || response.error) {
                             alert('Error occured');
                        } else {
                             alert('Status updated Successfully');
                        }
                   });
            }

thank you

Recommended Answers

All 11 Replies

This looks to be very specific to the api and what variables it can handle. I believe that you are using the an object format slightly wrong. Try this change

message: body, message: attachment

.

This way the properties of message would be message.body and message.attachment. The other way is message.body and attachment.attachment. That is two different objects. This is all based on my reading this right. I don't work with Facebook.

thank you very much for your reply, i have no understanding of coding, just trying to put it together. could you please show me on the original example i gave please?
how it will look please

thank you

This is what I meant.

FB.api('/me/feed', 'post', { message: body, message: attachment}, function(response) 
                        if (!response || response.error) {
                             alert('Error occured');
                        } else {
                             alert('Status updated Successfully');
                        }
                   });
            }

Give it a try.

thank you very very much
this means i would not need the text area to post what i need to post right?

so if i would need to insert an image on the left with a link attached to the image and next to the image can i add 3 or 4 lines of text and one of the line that has text could have a link embedded in?

how should this look to have something like that if possible?

{ message: body, message: attachment}, function(response)


many many text

First,did it work? Second I don't know. Tell me if it worked and I might be able to help more.

I will try it tonight when there is less people on the website but this looks like the other codes so i think it will work vey vey nicely, i am very exicited
thank you

I know i asked a lot but would you please show me how would this

{ message: body, message: attachment}, function(response)

look to have

insert an image on the left with a link attached to the image and next to the image can i add 3 or 4 lines of text and one of the line that has text could have a link embedded in?

Thank you

Ley me start again by saying I am not familiar with the api. All of this advice comes from general experience and a look at the page you show in your code. Therefore, if I had to guess, substitute this code and try it.

'media': [{ 'type': 'image', 'src': '<A href="http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg'" rel=nofollow>http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg'</A>, 'href': '<A href="http://bit.ly/187gO1'" rel=nofollow>http://bit.ly/187gO1'</A>},{'type': 'text', 'src': 'Insert your html and text here or it may be looking for a file name.'}] };

The part I added is

,{'type': 'text', 'src': 'Insert your html and text here or it may be looking for a file name.'}

. If I'm right, what is going on is you are uploading to the body of the document and replace it with everything that is contained in the media object. What my code is guessing at is that the type to use is a sub-object composed of the type of the media and the source(src) of the media. I separated the two objects with a comma which follows other languages syntax and enclosed them in curly braces.

If all of this works you should be able to add anything you like. I'm suspicious that the text might have to come from a file but try it without first. If it does work with a file you can use your favourite web page program to create the file. Hope this helps.

please don't get mad at me but now i am confused

i know you are gessing since you dont see alot of the code but i think this will do
{ message: body, message: attachment}, function(response)

so what i wanted to do was

Image (with link) ----text
-------------------------text (click on this will take them to the link)
-------------------------text
-------------------------text (click on this will take them to the link)

how would i show that with this below format. thank you

{ message: body, message: attachment}, function(response)

I very rarely even get miffed. What we are changing is inside the attachment. Here's the way I see that line. Insert a message (message.attachment) into my document(put it in after the body tags so I keep all the sidebars and things). I wouldn't be surprised to learn that there are other locations on the page that you could update or change.

in this case, let's suppose you want the right sidebar and the name just happens to be rightSidebar. Then it would go like this:

{ message: rightSidebar, message: attachment}, function(response)

Now, I'm going to stop guessing.

it did not work, may be i confused you below is the original code and it works with this
<form name="statusUpdate" action="" method="">
<textarea name="status" id="status" rows="4" cols="50"></textarea>

<input type="button" onclick="updateStatusViaJavascriptAPICalling(); return false;" value="Update Status via Facebook Javascript Library" />

since i cannot put any image or link to text area i was hoping something could be added to below code to have the message inside rather then looking in this form

thank you

}
            function updateStatusViaJavascriptAPICalling(){
                var status  =   document.getElementById('status').value;
                    FB.api('/me/feed', 'post', { message: status }, function(response) {
                        if (!response || response.error) {
                             alert('Error occured');
                        } else {
                             alert('Status updated Successfully');
                        }
                   });
            }

I found below code, maybe that's what you were trying to tell me in the first place

to below code how could i add more line of text to the body of the message like line 1, line 2 line 3 etc. one of them with a link and include an image as well

thank you

var body = 'Reading Connect JS documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
 if (!response || response.error) {
 alert('Error occured');
 } else {
 alert('Post ID: ' + response.id);
 }
 });
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.