stipe108
stipe108

Reputation: 1650

Facebook iOS SDK 3.1: "Error: HTTP status code: 400"

I am running the Facebook SDK 3.1 on Xcode 4.5GM with iOS6 simulator. I connect to FB in the iOS settings and successfully FB connect in my app using the new iOS6 FBConnect UI. I have an access token, can see my friends, send app requests, post to my wall, etc. However, every time I initiate any sort of FBURLConnection is made, I see this printed to my console:

Error: HTTP status code: 400

I went into the FB code and printed the reponse when this error is printed and I get:

{
    body =     {
        error =         {
            code = 100;
            message = "(#100) The parameter 'attribution' is required for the 'mobile_app_install' activity";
            type = OAuthException;
        };
    };
    code = 400;
}

Does anyone know how to resolve this? All functionality seems to work, but I keep seeing this spam my console.

Upvotes: 17

Views: 10908

Answers (6)

Donn Lee
Donn Lee

Reputation: 3149

After much troubleshooting and looking at all the suggestions on Stackoverflow, I got this error 400 (error.code = 5) thing resolved. The solution in my case was to make sure the params (aka postParams) included in my startWithGraphPath call had exactly the params supported by the type of content being posted.

More specifically, I was posting a link to me/feed with the @"ref" key (typically used for tracking with FB Insights).

After removing the @"ref" key, startWithGraphPath succeeded.

NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"Test NAME field (from ios app)", @"name",
                                   @"Test caption", @"caption",
                                   @"Test description", @"description",
                                   @"http://example.com/test1.html", @"link",
                                   @"http://example.com/water.jpg", @"picture",
                                   // @"foo", @"ref",  // WRONG!
                                   nil];

[FBRequestConnection startWithGraphPath:@"me/feed"
                             parameters:postParams
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)

My activeSession (and all other possible culprits) checked-out OK.

Upvotes: 2

brainondev
brainondev

Reputation: 1117

I discovered that Status Code 400 is also thrown with FBErrorHTTPError when something go wrong with Optional Properties in Define Action Type fieldset, within the Facebook=>Open Graph definition panel.

In my case I was posting an action object without a property marked as isRequired. Be also aware for isArray option and in general, for right matching with what you're sending.

Upvotes: 0

Joakim Engstrom
Joakim Engstrom

Reputation: 6393

This is the same as my answer from here: Facebook SDK 3.1 - Error: HTTP status code: 400

But it could help people still getting the 400 error.

The original issue was resolved by Facebook just after the 3.1 SDK was released.

But some are still having issues, if you have this issue you should check the login flow, and look at facebooks examples, if you are still having issues this could be a hint to a solution.

I got the 400 error when I do not have authorization to get to my information. The strange thing is that I get an accessToken and even a valid login (this is because I structured my code, with the help according to Scrumptious example and I did a valid login when the Session state is open).

The FBSessionState is only opened for like a second and then it changes to closed with an 400 Error.

With iOS6 native login you get the permission alert when you ask for it, and then the phone remember that choice for 24 hours. But if the user logs in to the facebook home-page and then deletes permission for the application the phone will remember that setting for 24 hours, regardless if you re-install the app or not.

This I found out after some hours of debugging, since I allowed the application from the Settings in iOS, but I could not post, and since I deleted the permission from the facebook privacy, and the alert would not show again there was nothing I could do but to manually give me permissions via a debug tool or wait 24 hours so I could accept the facebook-permission alert again.

Upvotes: 0

Anthony Dmitriyev
Anthony Dmitriyev

Reputation: 673

Right after the session is created do this:

[FBSession setActiveSession:session];

Upvotes: 18

Jason Clark
Jason Clark

Reputation: 1343

This error reflected a bug on the server, which was fixed shortly after the 3.1 release was published. At this point there should be no more failures coming from this request. Hope this helps!

Upvotes: -2

cbowns
cbowns

Reputation: 6375

As best as I can tell, this is a bug introduced in the 3.1 SDK. Looking at the network traffic with Charles, they’re trying to POST to graph.facebook.com/[user id]/activities but it’s failing.

Upvotes: 3

Related Questions