What is Twitter's duplicate tweet error code? - iphone

In my iphone app i am using Twitter-OAuth-iPhone to post and retrieve data from Twitter. The problem is that when someone wants to post a tweet twice(maybe by mistake) i need to tell him that the tweet was already posted.
when i do this i receive a 403 error from Twitter:
request failed with error Error
Domain=HTTP Code=403 "The operation
couldn’t be completed. (HTTP error
403.)"
the message doesn't tell me that i tried to post a duplicate Tweet. The 403 code, as specified here, is used when requests are being denied due to update limits.
A solution that i thought of is to keep in my app a list of tweets that where posted (an archive) that will be checked every time a new tweet is sent. The problem with this solution is that if someone is updating his twitter status from the web or other app it will fail because the archive from my app will not be updated.
I found a comment that says that the 403 code is just for duplicate tweets, but the documentation says otherwise.
EDIT:
on https://github.com/mattgemmell/MGTwitterEngine it says that:
In these cases you'll receive a call
to requestFailed:withError: which will
include an NSError object detailing
the error. Twitter usually returns
meaningful HTTP error codes (like 404
for 'user not found', etc), and in
that case the -domain of the NSError
will be "HTTP" and the -code will be
the relevant HTTP status code. The
userInfo of the NSError will contain a
key "body" that may contain the
response body and "response" which
will contain the NSHTTPURLResponse.
This makes it really, really easy to
know what's happening with your
connections.
but the userInfo attribute of the NSError that i receive in my app is null.

The problem is that Twitter-OAuth-iPhone for 4xx responses does not return the response body.
A solution could be to modify the MGTwitterEngine to provide the full error message. An example can be found here.

Related

What should be the response status code when data present in body is not found in DB

The request sent to api is :
url: /users/{userid}respource/{resourceid}
method: POST
body: {SubResourceId: 6, Message: ''}
So it is a post api. It creates some mapping of user and resource and subresource.
In this case if user or resource is not found , then api returns 404. But what should be the status code if subresource(which is passed in Body) is not found in DB?
I think you should use a 4** error, because it is a client error, they are referencing a non-existent subresource. If you look at the definitions of the HTTP status errors you see that for example 400 bad request means bad syntax, where the client should not try the same request again. However a 404 means not found, yet it might be available in the future so the request can be tried again at a later time.
In all cases there should be an informative message offering more detail if available. So in this case you should probably send a 404 and a message explaining that the subresource cannot be found. Basically you are passing on a 404 from a deeper level.
There is an arguement to be made that 'the resource' that you refer to in the URI was found, and that 404 is not perfect. However looking at the various status codes available in the w3c Definitions there does not seem to be a more appropriate one.
The other option I would consider is a 500, internal server error. You could argue that the server should expect a request with a valid subresourceid. Since the subresource does not exist, the server cannot further process the request. Again, as long as their is a clear error message this can work, but it feels like more of a stretch than the 404.
But most importably, make sure you are consistent when it comes to error handling in your API(s).
Ideally the response code should be 200 with message saying that no sub-resource was found, it can also be "204 No Content". you can read more about it at wiki link.
It needs to be consistent with Response codes you have been using throughout the application.

Facebook error: "(#100) Invalid parameter", "OAuthException", "code":100

In my messenger platform app, when I make this request:
GET https://graph.facebook.com/v2.8/${psid}?access_token=PAGE_ACCESS_TOKEN
(to get users public info based on their PSID), sometimes Facebook returns this error:
'There is an error when trying to get the user\'s info from Messenger:\nError: failed [400] {"error":{"message":"(#100) Invalid parameter","type":"OAuthException","code":100,"fbtrace_id":"FpUUkuX0egc"}}'
I have no idea why this happens, because when I saw the error then I manually made the same request (by using POSTMAN), I got the correct result (user public profile) with no error.
Maybe you can check if POSTMAN is sending something in the headers in a different way that you are doing. It happened to me something similar and it was that POSTMAN was "correcting" something.
Compare the request from POSTMAN and the one you are doing with your app side by side.
If that doesn't work, let me know and I'll look into another option. :)

What status code should be sent when a user tries to sign up with a username that already exists?

I was thinking 403. From http://www.restapitutorial.com/httpstatuscodes.html:
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
Edit: Endpoint - POST /users.
The normal HTTP error code for situations like this is 409 Conflict:
The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough
information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.
This should be issued in response to a POST or PUT, typically as part of some sort of RESTful API. It should include a useful error message in addition to the status, and the error should be appropriately encoded (e.g. with XML or JSON).
Obscure HTTP errors are less useful in front-end web services. If you are developing a user-facing website, it's preferable to simply deliver an HTML page explaining the problem with a standard 200 OK.
If you are creating a REST API to create accounts, I would expect the request to be something like:
POST /accounts HTTP/1.1
{userid: "someone#example.com", password: "passw0rd!"}
In this case, I guess an appropriate response code would be 409 Conflict with an error description in the body
HTTP/1.1 409 Conflict
{ error: "Account already exists"}
That status code is for an HTTP error, not what you need. Also, it would be very unhelpful as it does not describe the problem at all.
Why not just send:
Username already exists! Please select another.
403 is an ok response in my opinion. 409 and 412 are also possible choices.

How to resolve error: "The post’s action links must be valid URLs"

Using the latest version of ShareKit to post URLs like so:
[SHKFacebook shareURL:[NSURL URLWithString:#"http://www.google.com"]];
is resulting in the following error message being displayed (in a web view):
Application response error
The post’s action links must be valid URLs. You can see this because you are one of the developers of the app.
What does this error message really mean, and (more importantly) how can it be fixed?
The problem occurs if 'SHKConfigMyAppURL' is not a valid URL.

Error while posting duplicate message in Twitter(MGTwitterEngine)

I am using MGTwitterEngine for iPhone to support twitter, I am getting error(403) while posting a message second time how to handle this issue.
That is.. Let the message is "what are you doing" I am posting using [mTwitterEngine sendUpdate:"what are you doing"] for first time it is posted successfully, if i want to post the same message again it is throwing 403 error.
How to handle this?
Can i put the alert "Duplicate message" if error no 403? Is 403 error for duplicate messages only?
Added : Is it possible to check if an message is already posted in MGTwitterEngine?
The 403 error is not only for duplicate message so that you cannot throw the error message to user.
http://developer.twitter.com/pages/responses_errors
You have to find the duplicate message in your application code by keeping the last updated message.