2

I am following the instructions presented in http://dalibornasevic.com/posts/35-how-to-send-private-messages-with-facebook-api to send message to my friend and currently testing from command line. Following is the code I am using

require 'xmpp4r_facebook'

id = '<my facebook id>@chat.facebook.com'
to = '<my friend facebook id>@chat.facebook.com'
body = "hello, Im not spam!"
subject = 'message from ruby'
message = Jabber::Message.new to, body
message.subject = subject

client = Jabber::Client.new Jabber::JID.new(id)
client.connect
client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client, '<App ID>',   '<access token got from https://developers.facebook.com/tools/explorer>', 'App Secret'), nil)

I get the error

 RuntimeError: not-authorized
      from /Users/apple/.rvm/gems/ruby-1.9.3-p194/gems/xmpp4r_facebook-0.1.1/lib/xmpp4r_facebook.rb:103:in `auth'
      from /Users/apple/.rvm/gems/ruby-1.9.3-p194/gems/xmpp4r-0.5/lib/xmpp4r/client.rb:171:in `auth_sasl'
      from (irb):12
      from /Users/apple/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
raju
  • 4,788
  • 15
  • 64
  • 119

1 Answers1

2

Sounds like you didn't give authorization for xmpp_login permission as the message says

not-authorized

If you have the correct permission it should work and you should get a response similar to

<iq xmlns='jabber:client' type='result' id='2027'> ... </> 

Inspect your access token with https://developers.facebook.com/tools/debug

phwd
  • 19,975
  • 5
  • 50
  • 78
  • no when I try to debug, I get the following scopes under it. email publish_actions read_mailbox sms user_about_me user_birthday user_education_history user_events user_hometown user_interests user_location user_notes user_subscriptions user_website user_work_history xmpp_login – raju Oct 12 '12 at 16:13
  • @santu could you post the response after `client.connect` – phwd Oct 12 '12 at 16:25
  • I was using the APP ID I got while registering my app(in https://developers.facebook.com/apps) in developers.facebook and got the error. But the App Id I got by inspecting my access token is different and worked. I am still not able to send message but also not getting error at that step. – raju Oct 12 '12 at 17:09
  • @santu then you are using two different applications. you can inspect the application ID with `http://graph.facebook.com/APP_ID` – phwd Oct 12 '12 at 17:13
  • when I use the appId I got form access token it said name: name: "Graph API Explorer", description: "A tool to help browse objects within the Facebook Graph API, manage permissions, obtain access tokens and learn how it all works.", category: "Utilities", How do I get secret token for this? I am still using the secret token of the custom app I created along with this which might be causing the problem. While for the custom app I created it showed custom name and namespace I gave while creating. – raju Oct 12 '12 at 17:16
  • @santu you don't as I keep saying, you are using **two different apps** please use your application id. When using the Graph API Explorer tool you need to use the drop down menu (on the right) to change to your application. The reason it didn't work was because you used the access token for the Graph API Explorer App instead of your own application. – phwd Oct 12 '12 at 17:35
  • 1
    thanks you figured it out. i was using access token of graph api instead of my app. – raju Oct 12 '12 at 18:02
  • I am still having the problem though the current problem is different from the one I mentioned in this thread. Started a new question, in http://stackoverflow.com/questions/12864884/not-able-to-send-facebook-message-using-xmpp4r-facebook – raju Oct 12 '12 at 18:33