I am trying to post message to Tumblr through iOS app
written below code getting error.
NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:
#"Titulo",#"title",
#"Este es el body",#"body",nil];
[[TMAPIClient sharedInstance] post:#"blogName" type:#"text" parameters:parameters callback:^(id var, NSError *error){
NSLog(#"Error %#",error);
}];
getting following error
Error Domain=Request failed Code=401 "The operation couldn’t be completed. (Request failed error 401.)"
This is because you are not authenticated by Tubmlr.
You can refer to it here.
Unable to post a photo using the Tumblr SDK example
Related
I'm creating a watch application which records an audio and play that audio. The recorded audio is saved in the Apps Groups and I used the following code for playing the audio.
- (void)playAudio
{
// Playing the audio from the url using the default controller
[self presentMediaPlayerControllerWithURL:self.audioFileURL options:#{WKMediaPlayerControllerOptionsAutoplayKey : #YES} completion:^(BOOL didPlayToEnd, NSTimeInterval endTime, NSError * _Nullable error) {
NSLog(#"Error = %#",error);
}];
}
Unfortunately I am getting the following error and the player controller get dismissed immediately.
Error Domain=com.apple.watchkit.errors Code=4 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (1), NSUnderlyingError=0x16daa810 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}, NSLocalizedDescription=The operation could not be completed}.
Then I downloaded a sample project (WatchKitAudioRecorder Sample code) from Apple WatchOS Developer library but they are also having the same issue. I don't know why this is not working even in Apple Sample code :(
Finally I found that the data is not writing to the url path. Also should be written in the following path: Library/Caches/filename.extension
Here is a sample code, which may help someone.
- (void)writeAudioToAppGroupsWithData:(NSData *)audioData
{
// Writing the audio data to the App Groups
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:APP_GROUP_IDENTIFIER];
containerURL = [containerURL URLByAppendingPathComponent:[NSString stringWithFormat:DIRECTORY_PATH]];
[audioData writeToURL:containerURL atomically:YES];
}
In this case make sure that your DIRECTORY_PATH is Library/Caches/filename.extension. Eg: Library/Caches/Audio.mp3
I'm working on the CS193p coursework from Stanford (I'm not a Stanford student I'm just trying to learn), assignment number 5, where we have to get images from Flickr using calls to the Flickr api. I'm only trying to download a list of the pictures and print them out to the console, but I'm getting an NSURLErrorDomain with code -1005. The error message I am printing out is below:
error: Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x7f9449c83df0 {NSErrorFailingURLStringKey=https://api.flickr.com/services/rest/?method=flickr.places.getTopPlacesList&place_type_id=7&format=json&nojsoncallback=1&api_key=4f9c3155b34836b2ac15318d98b93f3a, NSErrorFailingURLKey=https://api.flickr.com/services/rest/?method=flickr.places.getTopPlacesList&place_type_id=7&format=json&nojsoncallback=1&api_key=4f9c3155b34836b2ac15318d98b93f3a, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x7f9449c7fca0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}
The Flickr API call is happening in the following method:
NSURLSession *urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
NSURLSessionDownloadTask *downloadTask = [urlSession downloadTaskWithURL:[FlickrFetcherHelper URLforTopPlaces] completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSArray *topPlaces;
if (!error) {
topPlaces = [[NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:location] options:0 error:&error] valueForKeyPath:FLICKR_RESULTS_PLACES];
}
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(topPlaces, error);
});
}];
[downloadTask resume];
I'm using xCode 6, not sure if that has anything to do with the problem. The same code was working a couple days ago, and I don't think I changed anything that would mess it up, but it clearly has.
Are you using the iOS8 (iPhone 6 for example) simulator? If so, try changing to iPhone 5s. I was having the same problem and switched my simulator and all worked well again. I tried this after reading the following feedback: https://github.com/AFNetworking/AFNetworking/issues/2314
Switch to iOS Simulator and do "Reset Content and Settings ..." from top menu.
I am trying to do a simple post for a login screen. I post an email address and password. This gives me a JSON back with status-codes. If this code is 200 it also contains a person object. If it is something else it contains an error object.
I have this code for posting.
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:#"http://******.com.be/nl/webservice/company-user/login/apikey/key**"]];
NSDictionary *dictionary = #{ #"email": _txtLogin.text, #"pwd": _txtPass.text};
NSMutableURLRequest *request = [manager requestWithObject:nil method:RKRequestMethodPOST path:nil parameters:dictionary];
RKObjectRequestOperation *operation = [manager objectRequestOperationWithRequest:request success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(#"Loading mapping result: %#", result);
}
failure:nil];
[operation start];
But this code is causing the following error.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: route'
*** First throw call stack:
Could anybody help me? I'm new to restkit.
Kind regards
You're trying to post an object using automatic routing, however, your object is nil. Therefore, it will rely on the path parameter to work out where to POST to. This is also nil.
You need to create the object manager with a common base URL, eg. http://******.com.be/nl/webservice/company-user and supply your method with the path parameter /login/apikey/key**
As Mountain Lion now officialy has Facebook integrated I wanted to play a little bit with Accounts.framework and Social.framework of OS X.
I set up an App in the Facebook Developer App and used the following code to request access to the Facebook Accounts of the logged in user:
ACAccountStore *acStore = [[ACAccountStore alloc] init];
ACAccountType *accType = [acStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:FB_APP_ID, ACFacebookAppIdKey, #"read_stream, publish_stream", ACFacebookPermissionsKey, ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];
[acStore requestAccessToAccountsWithType:accType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(#"Accounts: %#", acStore.accounts);
NSLog(#"Access granted");
} else {
NSLog(#"Access denied");
}
}];
Now I always get the error Error Domain=XPCObjectsErrorDomain Code=2 "The operation couldn’t be completed. (XPCObjectsErrorDomain error 2.)"
When I launched the App from Xcode the first 2-3 times, OS X displayed the confirmation dialog "XYZ wants to access your Facebook Accounts", I clicked ok and I got an error saying something like "The Application is not yet installed". This error now "disappeared" and I'm getting the error noted above.
My question is: Do I have to configure something special in my Xcode Project (Info.plist) or in the Facebook Developer App to make it work with OS X? Or am I missing something in the code? Samples and Tutorials regarding this seem to be very rare :-/
I already watched the WWDC 2012 Video about the Twitter/Facebook Integration but it uses almost exactly the code I used.
Any help is appreciated :-)
Cheers,
Björn
Update
I solved the issue, I just did not read the docs carefully enough ;-) I have to pass the permissions as an NSArray and not as a string. I've modified the options dictionary to look like this:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
FB_APP_ID, ACFacebookAppIdKey,
[NSArray arrayWithObjects:#"read_stream", #"publish_stream", #"email", #"user_likes", nil], ACFacebookPermissionsKey,
ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];
Now OS X shows an alert that asks me if I want to allow the App to post to Facebook on my behalf, I click OK and a new error appears resulting in no access to the Facebook accounts:
Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: The app must ask for a basic read permission at install time."
I already modified the permissions to be just email or just user_likes but it all resulted in the same error. If I only request access to read_stream the access gets granted but results in the OAuth error 190 with the message Error validating access token: User XXXXXX has not authorized application XXXXXX.
Update 2:
I now solved all my problems, see my answer below.
Alright, I finally solved it :-)
When you first request access to a users Facebook accounts, you may only request permissions from the user listed under "User and Friend permissions" in Facebook's Permission Reference.
Once the user granted access and with that also installed the application on Facebook, you may request any additional permissions required by your App. It's important that you may not ask for read and write permissions at the same time, one after the other! So requesting the permission read_stream and publish_stream in the same request will not work.
This is the basically the code I used:
self.store = [[ACAccountStore alloc] init];
ACAccountType *accType = [self.store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:
FB_APP_ID, ACFacebookAppIdKey,
[NSArray arrayWithObjects:#"email", #"user_about_me", #"user_likes", nil], ACFacebookPermissionsKey, ACFacebookAudienceFriends, ACFacebookAudienceKey, nil];
[self.store requestAccessToAccountsWithType:accType options:options completion:^(BOOL granted, NSError *error) {
if (granted && error == nil) {
self.accounts = self.store.accounts;
[options setObject:[NSArray arrayWithObjects:#"read_stream, read_mailbox, read_requests", nil] forKey:ACFacebookPermissionsKey];
[self.store requestAccessToAccountsWithType:accType options:options completion:^(BOOL granted, NSError *error) {
if (granted && error == nil) {
completionHandler(granted, error);
} else {
NSLog(#"Access denied 2");
NSLog(#"%#", [error description]);
}
}];
} else {
NSLog(#"Error: %#", [error description]);
NSLog(#"Access denied");
}
}];
Hope this will help somebody :-)
I would like to add that there is an additional caveat in the Facebook docs:
// if a user has *never* logged into your app, you MUST include one of
// "email", "user_location", or "user_birthday". Other read
// permissions can also be included here.
Failure to do this leads to the same error.
I'm trying to direct upload a video to Youtube via the Youtube API. I can't figure out where the problem is...is it my request URL syntax? Is there something wrong with the way I'm adding the video file to the body? (I'm using MKNetworkkit as my request engine.)
Here is my code:
//*********************************************************
//* Setup the request URL and params
//*********************************************************
NSString *baseUrl = #"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
NSString *_accessToken = // the google API access token
NSString *xml =
#"<?xml version='1.0'>"
"<entry xmlns='http://www.w3.org/2005/Atom'"
"xmlns:media='http://search.yahoo.com/mrss/'"
"xmlns:yt='http://gdata.youtube.com/schemas/2007'/>"
"<media:group>"
"<media:title type='plain'>My Video Title</media:title>"
"<media:description type='plain'>"
"This is a test video. Hopefully it'll upload to Youtube succesfully."
"</media:description>"
"<media:category"
"scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>People"
"</media:category>"
"<media:keywords>test, video</media:keywords>"
"</media:group>"
"</entry>";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_accessToken, #"access_token",
myYouTubeDeveloperKey, #"DEVELOPER_KEY",
#"vid1.mp4", #"VIDEO_FILENAME",
xml, #"API_XML_Request",
nil];
//*********************************************************
//* Configure the request
//*********************************************************
MKNetworkOperation *op = [globalMKNetworkEngine operationWithURLString:baseUrl params:params httpMethod:#"POST"];
[op addFile:[[self getVideoFileURL] absoluteString] forKey:#"Binary File Data"];
[op onUploadProgressChanged:^(double progress) {
NSLog(#"progress: %#", progress);
[uploadProgressBar setProgress:progress animated:YES];
}];
[op onCompletion:^(MKNetworkOperation *operation) {
//*********************************************************
//* On success, do this
//*********************************************************
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"Success!");
});
} onError:^(NSError *error) {
DLog(#"%#", [error localizedDescription]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Uh oh..." message:#"There was a network error. Please try again later." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}];
[globalMKNetworkEngine enqueueOperation:op];
Here is the response as reported by MKNetworkKit:
Danceplanet[16449:707] -[MKNetworkOperation operationFailedWithError:]
Request
-------
curl -X POST "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads" \
-F "VIDEO_FILENAME=vid1" -F "DEVELOPER_KEY=(the developer key is here)" \
-F "access_token=(an access token)" -F "API_XML_Request=<?xml version='1.0'>\
<entry xmlns='http://www.w3.org/2005/Atom'xmlns:media='http://search.yahoo.com/mrss/'xmlns:yt='http://gdata.youtube.com/schemas/2007'/>\
<media:group>\
<media:title type='plain'>My Video Title</media:title>\
<media:description type='plain'>This is a test video. Hopefully it'll upload to Youtube succesfully.</media:description>\
<media:categoryscheme='http://gdata.youtube.com/schemas/2007/categories.cat'>People</media:category>\
<media:keywords>test, video</media:keywords>\
</media:group>\
</entry>" \
-F "Binary File Data=#file://localhost/var/mobile/Applications/BBD79FFD-01D5-402C-995A-D9F9CE61F312/Documents/savedVideos/vid1.mp4;type=application/octet-stream"
--------
Response
--------
Invalid Request
, [The operation couldn’t be completed. (NSURLErrorDomain error 400.)]
Danceplanet[16449:707] __block_global_3 [Line 167] The operation couldn’t be completed. (NSURLErrorDomain error 400.)
Danceplanet[16449:707] -[MKNetworkOperation operationFailedWithError:] [Line 1283] State: 0`
I think the problem might be whit the NSString
NSString * xmlEx =#"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<Data xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"
"<MediaFile>"
"<FileName>%#</FileName>"
"<Folder>%#</Folder>"
"</MediaFile>"
"</Data>"
This is how i write xml to string before i post. The problem might be with the special characters. Compere the XML version characters.
I've given up on this approach and am now using the Google obj-c client library instead.