Photobucket iOS API Authentication - ios

I'm trying to integrate Photobucket iOS API with my project. I requested and already have consumer key and secret. But I have a problem with authentication (may be there is will be problems with upload). Please look at my code.
At first init photobucket manager:
manager = [[PhotobucketAPI alloc] initWithConsumerKey:photobucketConsumerKey
consumerSecret:photobucketConsumerSecret
globalErrorDelegate:self];
Then request authentication:
[manager loginDirectAndStoreForUsername:login
password:pass
delegate:self
didSucceedSelector:#selector(didSucceedLogin:)
didFailSelector:#selector(didFailLogin:)
downloadProgressDelegate:self
uploadProgressDelegate:self];
This is how look like method didFailLogin::
- (void)didFailLogin:(NSError *)error
{
if (error)
NSLog(#"Error: %#", error);
}
And all time I'm getting this error:
Error Domain=Authentication failed. Code=999 "The operation couldn’t
be completed. (Authentication failed. error 999.)"
So what I doing wrong?

Related

Retweet using STTwitter API

I have tried to add the retweet concept in my application using STTwitter API with following method after user authentication:
[twitter postStatusRetweetWithID:[NSString stringWithFormat:#"691544087921606656"] successBlock:^(NSDictionary *status) {
NSLog(#"status..%#",status);
} errorBlock:^(NSError *error) {
NSLog(#"error..%#",error);
}];
But it is showing following error:
Error Domain=STTwitterTwitterErrorDomain Code=220 "Your
credentials do not allow access to this resource."
UserInfo={NSUnderlyingError=0x7b170ca0 {Error Domain=STHTTPRequest
Code=403 "HTTP Status 403: Forbidden"
UserInfo={NSLocalizedDescription=HTTP Status 403: Forbidden}},
NSLocalizedDescription=Your credentials do not allow access to this
resource.}
If anyone has experienced with the STTwitter API. Suggest me some idea to get rid from this error.
Thanks in advance.

Spotify API getting starred list not authorized

I'm using the Spotify iOS SDK and trying to get use this function starredListForUserInSession:callback: to find a user's starred list once they have logged in.
The actual logging in of the user is working correctly, as I am able to stream Spotify tracks and a valid SPTSession is returned. I am including both the streaming and the playlist reading scopes as seen below:
SPTAuth *auth = [SPTAuth defaultInstance];
NSURL *loginPageURL = [auth loginURLForClientId:kSpotifyClientID
declaredRedirectURL:[NSURL URLWithString:kSpotifyCallbackURL]
scopes:#[SPTAuthStreamingScope, SPTAuthPlaylistReadPrivateScope]];
However, when I use the function:
[SPTRequest starredListForUserInSession:[AppDelegate sharedAccounts].spotifySession callback:^(NSError *error, id object) {
if (error) {
NSLog(#"%#", error);
}
}];
I consistently receive the following error:
"The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x7a8cbf50 {NSErrorFailingURLKey=https://api.spotify.com/v1/users/(null)/starred, NSErrorFailingURLStringKey=https://api.spotify.com/v1/users/(null)/starred, NSUnderlyingError=0x7a6d5b60 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)"
When I looked this up, it said that it means this request requires authentication, though the user has already been authenticated with the presumably correct scope. What am I missing?

Spotify createPlaylistWithName results in forbidden error

I am trying to create a playlist with the Spotify iOS SDK, but am receiving the following error:
Error Domain=com.spotify.ios-sdk Code=403 "forbidden" UserInfo=0x7fb9eb577cf0 {NSLocalizedDescription=forbidden}
Here is the way that I am trying to create the playlist:
[SPTRequest playlistsForUserInSession:session callback:^(NSError *error, SPTPlaylistList *myPublicPlaylists) {
[myPublicPlaylists createPlaylistWithName:playlistName publicFlag:FALSE session:session callback:^(NSError *error, SPTPlaylistSnapshot *myRequestedPlaylist) {
if (error != nil) {
return;
}
success(myRequestedPlaylist);
}];
}];
I have verified that the session is valid and the SPTPlaylistlist returned from playlistsForUserInSession is correct. What is the correct method for creating a playlist to avoid this error?
As per the Readme from the iOS SDK release, "When connecting a user to your app, you must provide the scopes your application needs to operate. A scope is a permission to access a certain part of a user's account, and if you don't ask for the scopes you need you will receive permission denied errors when trying to perform various tasks."
In this case, it is necessary to give permissions for either (or both) SPTAuthPlaylistModifyPrivateScope and SPTAuthPlaylistModifyPublicScope.
For example:
// Create SPTAuth instance; create login URL and open it
SPTAuth *auth = [SPTAuth defaultInstance];
NSURL *loginURL = [auth loginURLForClientId:kClientId
declaredRedirectURL:[NSURL URLWithString:kCallbackURL]
scopes:#[SPTAuthStreamingScope, SPTAuthPlaylistModifyPrivateScope, SPTAuthPlaylistModifyPublicScope]];

Strongloop iOS User Creation Error

I'm trying to create and save a test user in server with this code:
LBRESTAdapter *adapter = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).adapter;
if (adapter) {
TeacherRepository *repo = (TeacherRepository *)[adapter repositoryWithClass:[TeacherRepository class]];
if (repo) {
Teacher *st = (Teacher *)[repo createUserWithEmail:#"test#test.com" password:#"test"];
if (st) {
[st saveWithSuccess:^{
NSLog(#"Saved in server!");
} failure:^(NSError *error) {
NSLog(#"Error: %#", error.description);
}];
}
}
}
but I keep on getting this error response:
Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 404"
I have searched for this error and similar others, but couldn't find anything that would solve my problem, so what could be causing this?
The HTTP Status Code of 404 means that the resource was not found:
404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.
It would appear that there is an error in the building of the URL in your AFNetworking code. You haven't shared that portion of code, so it's hard to comment on the specifics. I think if you log the entire error object (not just error.description) it will show you what URL it attempted to use unsuccessfully.

AFNetworking with Unreliable wifi - Detecting / Retrying connections when they timeout

I'm using AFNetworking in my app to connect / download data from a web service. This app is deployed via Enterprise deployment to users at various locations. At one of the locations where people use our app, the wifi network seems to randomly go down / come back up in a few seconds. In these cases, the requirement was to retry a request thrice before giving up and failing. I've got the retry part of it working fine, but have some problems detecting a network failure. Some code:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation, id responseObject) {
[self parseResponse:operation.responseString];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self messageFailureWithCode:error.code
reason:[NSString stringWithFormat:#"%#", error]];
}
];
The error code I'm retrying on is NSURLErrorTimedOut. But I just got another log file which indicated a failure with the following error: -1003 "A server with the specified hostname could not be found."
I could add this code to my list too, but I wanted to be sure that I'm capturing all the errors and not just handling them as they appear. I was looking through the NSURLError.h file and found the following error codes that vaguely look like they could be caused by a network failure.
Can someone help me figuring out under what conditions each error is triggered and if I'm missing any error codes? The list is below:
NSURLErrorCannotFindHost
NSURLErrorTimedOut
NSURLErrorCannotConnectToHost
NSURLErrorNetworkConnectionLost
NSURLErrorDNSLookupFailed
NSURLErrorResourceUnavailable
NSURLErrorNotConnectedToInternet
Thanks,
Teja.
It sounds like you could safely just retry every failure with an error domain of NSURLErrorDomain (exempting the case where an operation was cancelled). That should cover all of those cases.

Resources