CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
login and post image on facebook

 



gerble1000
User

Oct 3, 2012, 10:34 AM

Post #1 of 14 (2737 views)
login and post image on facebook Can't Post

would it be tricky to make a script to login to facebook and post an image and message .
if so where would i start and would anybody be interested in a few pound for making me a script to do this.

also the image is already on the net so a simple url would have to be used


(This post was edited by gerble1000 on Oct 3, 2012, 10:53 AM)


wickedxter
User

Oct 3, 2012, 1:50 PM

Post #2 of 14 (2729 views)
Re: [gerble1000] login and post image on facebook [In reply to] Can't Post

you can use WWW::Mechanize to do this, but this kinda seems shady tho..


gerble1000
User

Oct 3, 2012, 1:55 PM

Post #3 of 14 (2726 views)
Re: [wickedxter] login and post image on facebook [In reply to] Can't Post

i thought this, but didnt think that i would be able to do it with mech. i shall have a play tomorow with mech and see how far i get. chears


gerble1000
User

Oct 4, 2012, 2:58 AM

Post #4 of 14 (2719 views)
Re: [wickedxter] login and post image on facebook [In reply to] Can't Post

ok i have managed to login and successfully post a message and link. here is my code.


Code
 
#!/strawberry/perl/bin/perl -w


use strict;
use WWW::Mechanize;
use HTTP::Cookies;

my $url = "http://www.facebook.com/groups/532874430060468/?_fb_noscript=1";
my $appurl = "http://www.facebook.com/groups/532874430060468/?_fb_noscript=1";

my $username = 'myemail';
my $password = 'mypassword';

my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_name('menubar_login');
$mech->field(email => $username);
$mech->field(pass => $password);
$mech->click();
my $facebook_content = $mech->content();
# go to an app url
$mech->get($appurl);
my $app_content = $mech->content();

my $message = "test message please ignore\n\nhttp://www.domainname.co.uk/10/thumb1.png";

$mech->field(message => $message);

$mech->click();


the problem i have now is having the message have a picture inside it. when i just post the link thats all i get is a clickable link.
is there a special command to do this


gerble1000
User

Oct 4, 2012, 9:19 AM

Post #5 of 14 (2710 views)
Re: [gerble1000] login and post image on facebook [In reply to] Can't Post

i have been trying for hours now. even tried the m.facebook.com mobile version and cant do it that way either.
any ideas would be appriciated.
the mobile way seems to be a better way as it has less going on.
just an input for photo and a message.
but when i anilise the results it says incompatable browser for uploading images.


Zhris
Enthusiast

Oct 4, 2012, 11:09 AM

Post #6 of 14 (2708 views)
Re: [gerble1000] login and post image on facebook [In reply to] Can't Post

Hi,

Facebook::Graph http://search.cpan.org/~rizen/Facebook-Graph-1.0401/lib/Facebook/Graph.pm should be capable of performing your task. I have used this module in order to integrate sites with Facebook on many occasions. Its definately worth looking through the Facebook developers guide, particularly the open graph actions.

Chris


gerble1000
User

Oct 4, 2012, 12:51 PM

Post #7 of 14 (2702 views)
Re: [Zhris] login and post image on facebook [In reply to] Can't Post

i have played and failed... i have now posted the project on freelancer and when it has been made i will post the script here for others to read, thanx anyway. ps the graph way is most likely the way forward but i got stuck on the tokens part.


gerble1000
User

Oct 8, 2012, 6:57 AM

Post #8 of 14 (2647 views)
Re: [gerble1000] login and post image on facebook [In reply to] Can't Post

as promissed i have got the scripted made for me and here it is


Code
#!/strawberry/perl/bin/perl -w 
use CGI::Carp qw( fatalsToBrowser );



use strict;
use warnings;
use Facebook::Graph;
use WWW::Mechanize;
use HTTP::Cookies;
use Crypt::SSLeay;
use WWW::Facebook::API;
use URI::Escape;
use Data::Dumper;
use CGI qw/ :standard /;



my $cookie_jar = HTTP::Cookies->new; #print $cookie_jar->as_string;

######################################################################
#
# SETTING PARAMS ####################################################
#--- Access token to be filled
my $access_token='';

#--- APP info to be filled
my $redirect_url=uri_escape('here');
my $facebook_application_secret='here';
my $facebook_application_id='here';


$access_token='here';
############ START AUTH - REQUEST ACCESS_TOKEN #########################
my $oauth_url = 'https://graph.facebook.com/oauth/access_token?client_id='.$facebook_application_id.'&client_secret='.$facebook_application_secret.'&grant_type=client_credentials';

##############FACEBOOK API FOR SCRAPE/POST ##############################
my $fb = Facebook::Graph->new(
secret => $facebook_application_secret,
app_id => $facebook_application_id,
postback => $redirect_url,
);


my $au=$fb->authorize();
my $uri = $fb
->authorize
->extend_permissions(qw(offline_access publish_stream))
->uri_as_string;


#my $token_response_object = $fb->request_access_token($au->postback);
## Setting Acces Token
$fb->access_token($access_token);


### FETCH USER/GROUP PAGE ########
my $user = $fb->fetch('me');
my $perl_page = $fb->fetch('here');


print STDOUT "FETCH ME: I'm $user->{name} and my ID is $user->{id} \n";

### POST IN MY HOME ########
#my $perl_page=$fb->add_post
# ->set_message('here')
# ->set_picture_uri('here')
# ->set_link_uri('here')
# ->set_link_name('here')
# ->set_link_caption('here')
# ->set_link_description('here')
# ->publish;

if ($perl_page->{_content}=~/error/)
{
print STDOUT "Error on posting on my wall: $perl_page->{_content}\n";
}
### POSTING ON ANOTHER WALL TO is the FB id ########
my $perl_page2=$fb->add_post #OK groups/here
->to('here') #ID of the wall in which you want to post to.
->set_message("here")
->set_picture_uri('here')
->set_link_uri('here')
->set_link_name('here')
->set_link_description('here')
->publish;
if ($perl_page->{_content}=~/error/)
{
print STDOUT "Error on posting on my here wall: $perl_page->{_content}\n";
}
#### POSTING ON MY HOME Message, picture,link,caption and descripion
#my $response = $fb->add_post
# ->set_message('here')
# ->set_picture_uri('here')
# ->set_link_uri('here')
# ->set_link_name('here')
# ->set_link_caption('here')
# ->set_link_description('here')
# ->publish;

my $a=1;
if ($perl_page->{_content}=~/error/)
{
print STDOUT "Error on posting on my wall: $perl_page->{_content}\n";
}


i have replace my personal data with "here" hope this helps someone else


gerble1000
User

Oct 8, 2012, 9:36 AM

Post #9 of 14 (2626 views)
Re: [Zhris] login and post image on facebook [In reply to] Can't Post

is there a reason why i cannot use the pound sign in posting onto the facebook wall. it comes up as an unrecognised simbol


gerble1000
User

Oct 14, 2012, 11:10 AM

Post #10 of 14 (2435 views)
Re: [Zhris] login and post image on facebook [In reply to] Can't Post

i got a problem.
the script is now not uploading to the group account.
i am ansure whats gone wrong as i dont get any errors.
could i get some pointers please.
i tried changing the access token and when i did i got an access token error. so i am assuming that its not that


gerble1000
User

Oct 15, 2012, 3:30 AM

Post #11 of 14 (2411 views)
Re: [gerble1000] login and post image on facebook [In reply to] Can't Post

it seems to be something wrong with set_picture_uri as when i disable all but set_message it works ok. i havnt changed anything in the account settings and the script is back to normal. i dont understand why it would suddenly stop working.

any ideas


Zhris
Enthusiast

Oct 15, 2012, 11:30 AM

Post #12 of 14 (2403 views)
Re: [gerble1000] login and post image on facebook [In reply to] Can't Post

Hi,

With regards to the symbol, not sure, try escaping it.

With regards to your code, from scanning through it, I cannot see anything that looks odd, especially as you say you have it mostly working. Its a little difficult to debug without being able to test your data under your exact conditions. Did you accept the publish stream permissions, and did it postback ok. Theres also the possibility that Facebook has updated their API hence breaking certain methods, although I might expect some kind of error.

Luckily, I haven't had to delve deep into Facebook::Graph / really only used it to retrieve information mostly via FQL. Unfortunately I don't have access to a Perl web environment with Facebook::Graph installed to play with your code outside of work.

Apologies I can't be of much help.

Chris


gerble1000
User

Oct 15, 2012, 12:39 PM

Post #13 of 14 (2400 views)
Re: [Zhris] login and post image on facebook [In reply to] Can't Post

thanx anyway :)
just figured it out.
after contacting the coder who written this for me.
we added a load of extra permissions in the facebook app section.
that sorted it strait away.
i basicly added every permission available. not sure if thats a good idea or not but it worked.


Zhris
Enthusiast

Oct 15, 2012, 1:33 PM

Post #14 of 14 (2397 views)
Re: [gerble1000] login and post image on facebook [In reply to] Can't Post

Ahh good to hear you sorted it. Its interesting because a code example I looked at to compare with your code, was very similar, and only used the publish stream permissions. Anyway, in case you find it useful, heres Facebook permissions documentation... http://developers.facebook.com/docs/reference/login/#permissions

Cheers,

Chris

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives