{"record":{"id":"ac9b4fc83f90b747","repo":"arsduo/koala","slug":"delete-requires-an-access-token","errorCode":null,"errorMessage":"Delete requires an access token","messagePattern":"Delete requires an access token","errorType":"exception","errorClass":"Koala::Facebook::AuthenticationError","httpStatus":null,"severity":"error","filePath":"lib/koala/api/graph_api_methods.rb","lineNumber":109,"sourceCode":"      # @see #put_connections\n      #\n      # @note put_object is (for historical reasons) the same as put_connections.\n      #       Please use put_connections; in a future version of Koala (2.0?),\n      #       put_object will issue a POST directly to an individual object, not to a connection.\n      def put_object(parent_object, connection_name, args = {}, options = {}, &block)\n        put_connections(parent_object, connection_name, args, options, &block)\n      end\n\n      # Delete an object from the Graph if you have appropriate permissions.\n      #\n      # @param id (see #get_object)\n      # @param options (see #get_object)\n      # @param block (see Koala::Facebook::API#api)\n      #\n      # @return true if successful, false (or an APIError) if not\n      def delete_object(id, options = {}, &block)\n        # Deletes the object with the given ID from the graph.\n        raise AuthenticationError.new(nil, nil, \"Delete requires an access token\") unless access_token\n        graph_call(id, {}, \"delete\", options, &block)\n      end\n\n      # Fetch information about a given connection (e.g. type of activity -- feed, events, photos, etc.)\n      # for a specific user.\n      # See {http://developers.facebook.com/docs/api Facebook's documentation} for a complete list of connections.\n      #\n      # @note to access connections like /user_id/CONNECTION/other_user_id,\n      #       simply pass \"CONNECTION/other_user_id\" as the connection_name\n      #\n      # @param id (see #get_object)\n      # @param connection_name what\n      # @param args any additional arguments\n      # @param options (see #get_object)\n      # @param block (see Koala::Facebook::API#api)\n      #\n      # @return [Koala::Facebook::API::GraphCollection] an array of object hashes (in most cases)\n      def get_connection(id, connection_name, args = {}, options = {}, &block)","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/arsduo/koala/blob/47d052063ef8b5644fb59e279da0b52687999f55/lib/koala/api/graph_api_methods.rb#L91-L127","documentation":"delete_object raises Koala::Facebook::AuthenticationError ('Delete requires an access token') when the API instance has no access_token (lib/koala/api/graph_api_methods.rb:109). Deleting a Graph object always requires an authenticated context, so Koala blocks the call client-side — the error is built with nil http_status, meaning no request was sent to Facebook. delete, collection helpers such as delete_all, and every other caller of delete_object pass through this same guard.","triggerScenarios":"api.delete_object('123_456'), api.delete('123_456'), or a graph collection's delete_all where the owning API was created without a token — e.g. Koala::Facebook::API.new followed by a delete, or a token variable that evaluated to nil at construction time.","commonSituations":"Cleanup/rollback jobs built on a tokenless API; user sessions whose token was cleared on logout but the delete request still arrives; specs constructing Koala::Facebook::API.new without stubbing a token; env var name typos that pass nil silently.","solutions":["Create the API with a valid access token: Koala::Facebook::API.new(token)","Verify the token value at the call site (session, ENV, credentials) — nil here is exactly what triggers the guard","If the token may be stale, validate it first with Koala::Facebook::OAuth.new(app_id, app_secret).debug_token(token)","Rescue Koala::Facebook::AuthenticationError and restart OAuth instead of letting the delete crash"],"exampleFix":"# before\napi = Koala::Facebook::API.new\napi.delete_object('1015550') # => AuthenticationError: Delete requires an access token\n\n# after\napi = Koala::Facebook::API.new(ENV.fetch('FB_TOKEN'))\napi.delete_object('1015550') # => true","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'delete_object requires an access token' unless api.access_token\napi.delete_object(id)","typeGuard":null,"tryCatchPattern":"begin\n  api.delete_object(id)\nrescue Koala::Facebook::AuthenticationError => e\n  # nil http_status => client-side guard: token missing at call time\n  clear_session_token_and_relogin!\nend","preventionTips":["Check api.access_token before destructive calls — nil should trigger re-auth, not a mid-request raise","Use ENV.fetch / Rails credentials with fail-fast so tokens are never silently nil","Wrap delete flows in AuthenticationError handling that clears the stale token and re-runs OAuth","Stub the access token in specs so delete_object reaches the mocked HTTP layer"],"tags":["authentication","access-token","delete","facebook-graph-api"],"backgroundTag":"missing-access-token","analyzedSha":"47d052063ef8b5644fb59e279da0b52687999f55","analyzedAt":"2026-08-23T10:19:03.891Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}