Search code examples
ruby-on-railsfacebookkoala

Facebook page posting - type: OAuthException, code: 2


I'm trying to test page posting from my app with Koala/Graph API.

I've already authed and persisted the users page access_token like so:

def facebook
        @vendor = current_vendor
        uid = request.env["omniauth.auth"]["uid"]
        fb_token = request.env["omniauth.auth"]["credentials"]["token"]

        @graph = Koala::Facebook::API.new(fb_token)
        pages = @graph.get_connections("me", "accounts")

        first_page_token = pages.first['access_token']

        @vendor.update_attributes(uid: uid, fb_token: fb_token, fb_page_token: first_page_token)

        redirect_to vendors_dashboard_path
end

I can confirm that this method is properly setting attributes after checking in the console and logs.

When I go to test a post to a page:

def post_to_facebook
    @graph = Koala::Facebook::API.new(current_vendor.fb_page_token)
    object = @graph.get_object('me')
    puts object # confirmed in the server logs that this object is the page.
    @graph.put_wall_post("feed test")
    flash[:success] = "Posted to Facebook."
    redirect_to :back
end

This results in:

type: OAuthException, code: 2, message: An unexpected error has occurred. Please retry your request later. [HTTP 500]

I have publish, manage pages, and read permissions (which are granted by the Facebook Test User after they auth).

Why can't I post to the users page?


Solution

  • What a frustrating waste of a couple hours. For some reason, when testing this feature the app had to be live to the public. That seems strange - why would a page created by a test user be publicly viewable? I tested posting as an individual, as an individual on a page etc. and never needed the Facebook app to be 'Live'. Stuff like this is generally par for the course when working with Facebook though.

    Easy to fix though:

    Developer Dashboard -> Select your app -> Status & Review -> Make your app 'Live'.