I'm using the GoogleDrive Objective-C SDK, and I'm running into an issue. I want to build up a path -> ID mapping structure, so I ask Drive for a list of all of a users files. Normally this works fine. But, in cases where users have very large amounts of files, the server returns an internal error. I can fix this by setting the maxResults property on my GTLQueryDrive to a lower number. When I do that, everything works as expected, EXCEPT that the nextPageToken (and nextLink) property of the GTLDriveFileList is nil. I believe I need this nextPageToken to continue grabbing file information. I have tried setting the fields property on my query to nil, to a string that includes nextPageToken, and to a string that does not include nextPageToken. The nextPageToken property appears to be nil in all cases. Is there something I am missing? Thanks!
Adding answer based on comment chain.
Here's a little sample that you can experiment with.
driveService.shouldFetchNextPages = YES;
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.maxResults = 5;
// queryTicket can be used to track the status of the request.
[driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket, GTLDriveFileList *files,
NSError *error) {
if (files) {
NSLog(#"Have response %#", files.items);
NSLog(#"Token %#", files.nextPageToken);
NSLog(#"Count %d", files.items.count);
}
}];
With shouldFetchNextPages set to YES, the result will not contain a nextPageToken. Instead, assuming you have more than 5 files (based on maxResults) you'll still get the full list, along with a message in the log file that will look something along the lines of:
Executing drive.files.list required fetching 4 pages; use a query with a larger maxResults for faster results
If you set shouldFetchNextPages to NO, the result will be capped at 5 results in this case, and nextPageToken will have a valid token for getting the next page in the result set.
Related
Is there a way to identify whether the logged in account is local account or active directory account on OS X? If yes, how can we retrieve the domain name?
You can create a CBUserIdentity for the user from their username:
CBUserIdentity* identity = [CBUserIdentity identityWithName:NSUserName() authority:[CBIdentityAuthority defaultIdentityAuthority]];
Then, you can obtain that user identity's authority:
CBIdentityAuthority* authority = identity.authority;
Then, you can see if that is the local authority (the alternative is the managed authority):
if ([authority isEqual:[CBIdentityAuthority localIdentityAuthority])
{
// user is local
}
else
{
// user is managed
}
The authority has a localizedName property, but that's not likely to include the domain name, I don't think. I don't know how to get that.
Update:
This is an approach using the Open Directory API:
ODSession* session = [ODSession defaultSession];
ODNode* node = [ODNode nodeWithSession:session type:kODNodeTypeAuthentication error:NULL];
ODQuery* query = [ODQuery queryWithNode:node forRecordTypes:kODRecordTypeUsers attribute:kODAttributeTypeRecordName matchType:kODMatchEqualTo queryValues:NSUserName() returnAttributes:kODAttributeTypeStandardOnly maximumResults:0 error:NULL];
NSArray* results = [query resultsAllowingPartial:NO error:NULL];
ODRecord* record = results.firstObject;
At this point, you can query the record for some of its attributes. One that may be of interest might be kODAttributeTypeMetaNodeLocation:
NSArray* attributes = [record valuesForAttribute:kODAttributeTypeMetaNodeLocation error:NULL];
NSString* attribute = attributes.firstObject;
For a local account, the meta node location should be "/Local/Default". I tested with an LDAP account and that gave ""/LDAPv3/my.ldap.server.example.com". I don't have an Active Directory account to test with.
Alternatively, you can try kODAttributeTypeMetaRecordName. For a local account, that returned nil. For an LDAP account, it gave the fully distinguished name: "uid=ken,ou=People,dc=example,dc=com". Again, I don't know what it would do for an Active Directory account.
You can log the record to see other attributes that are available. That will show the attribute keys as string values. You can look here to try to find a symbolic constant for the one(s) of interest, or check /System/Library/Frameworks/OpenDirectory.framework/Frameworks/CFOpenDirectory.framework/Headers/CFOpenDirectoryConstants.h for some which aren't documented.
Once you find what you really care about, you can maybe simplify the query by requesting just those instead of kODAttributeTypeStandardOnly. Also, you should consider running the query asynchronously rather than synchronously as I did in my example code.
For me the code:
NSMutableString *userDataDirectory = [[NSMutableString alloc] initWithString:NSHomeDirectory()];
NSLog(#"%#", userDataDirectory);
prints: /Users/jwlaughton
Is this what you're looking for?
I am trying to produce a request using afnetworking in objective c, however, it seems like the hardware that I am trying to connect to only applies requests when the parameters of the request are in a specific order. So I am wondering if there is a way to make the request so that the parameters are in a specific order. (As just doing it normally seems to jumble the sequence of the params up)
Here's my code:
NSDictionary *params = #{
#"param1" : #"bla",
#"param2" : #"bla2",
#"param3" : #"bla3"
};
[requestManager GET:#"somewhere" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
DLog(#"Success!");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
DLog(#"Fail: %#", error);
}];
It actually goes to success every time, its just that the request I had applied would be practically ignored.
The actual request body becomes something like "param3=bla3¶m1=bla1¶m2=bla2 etc which would be ignored as it seems.
You can't do that using the request manager in the way you currently are.
Instead, you would need to create the parameter list yourself, and then create a request from that. Then you could use AFN to handle the request transmission and response.
Note that the server shouldn't require a specific order and that this should be changed if possible. Note also that the dictionary of parameters has no order (even though you add the keys in a set order).
Keeping the order of the parameters have a great impact on server performance. This sounds silly at first, but just think about GET requests which contain the query string as part of the URL. Web servers can cache the response for the given URL. If you mess with the order of the parameters, the cache won't be as effective as it could be.
The case is even worse if you call an API from different platforms (iOS, Android, Web) and they all reorder the params, which means that the same content will be found on 3 different cache keys.
Keeping the order is a performance issue at the first place.
I am fetching an object from the persistentStoreManagedObjectContext and showing some of its value to my user within a UIView. That object, let's call it Book has an Author relationship. Whenever I am about to display that book, I check if the author is set or not. If it's not set, I do:
[[RKObjectManager sharedManager] getObjectsAtPath:[NSString stringWithFormat:#"/api/rest/userprofiles/%#/",_currentBook.authorID] parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {..}
Within the success callback, I want to do a:
_currentBook.author = mappingResult.firstObject;
if (![_currentBook.managedObjectContext saveToPersistentStore:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
}
However, I can't do _currentBook.author = mappingResult.firstObject; because I get:
Illegal attempt to establish a relationship between objects in different contexts
However, I know that this newly fetched Author is saved within the persistentStoreCoordinator, because I configured my RestKit to do so (or it's by default, I can't remember). So I don't want to create that object AGAIN, I would just want to get it's value within my currentContext which is persistentStoreManagedObjectContext. Do I have to use a NSFetchedResultsController just for that?
Edit
I already have a connection in the book to connect to the author, via the authorID, which I send back at the same time as getting the Book object from my server. However, it might be the case that the Author Object is not fetched yet, hence I keep that ID.
[bookMapping addConnectionForRelationship:#"author" connectedBy:#{ #"authorID": #"identifier" }];
However, even after that author is fetched, book.author is set to null, unless I REFETCH once again in the persistent storage.
You should get RestKit to connect the relationship using foreign key mapping based on the author id. That way all of the updates are made at the same time, in the same context, and saved before the mapping result is returned.
I'm working on a project that requires downloading a list of users from a server —JSON data created from a PHP script that reads a MySQL database— and I would like to inform the user of the progress of the request but onDownloadProgressChanged: never gets called when sending a GET request through operationWithPath:params:httpMethod:ssl: and I don't know if that is an intended behavior or not.
MKNetworkOperation *op = [self operationWithPath:kSPGetUserListPath params:nil httpMethod:#"GET" ssl:YES];
Should onDownloadProgressChanged: be called when I send a GET request with operationWithPath:params:httpMethod:ssl: or is it only called when downloading a file using addDownloadStream:?
Whenever I send a POST request with a file attached through addData: method of MKNetworkOperation the onUploadProgressChanged: method get called accordingly.
Thank you!!!
I had the same problem because missed something like the following MKNetworkEngine initializing in the main class:
self.sampleDownloader = [[ExampleDownloader alloc] initWithHostName:nil customHeaderFields:nil];
I'm developing an Server-Client application in Xcode 4.2
The application saves some user informations and sends them in a HTTP GET request to server via server url.
As response, I have text like this:
2011-12-30 15:44:02.120 smartHome[340:f803] {
button = 1;
key = 181abc88e57c37a42769;
message = (
{
ID = 1;
date = "2011-12-10 16:00:00";
message = asdf;
status = 1;
"user_id" = 2;
}
);
"wrong_user" = 0;
}
(2/Jan/2012)
Sorry for such confusing edits but i haven't overcome my deal yet. I need to parse this JSON text(i think it is called text:) and do some implemetations on the results.. I have to use, for example, the message object and its status value, if status equals to 1 i will trigger a Notification in my App. As like that, if the button comes me as a value with 1 i will send a POST to the server and request for the button id and title attributes..
There are a lot of tutorials about parsing but all i saw are about Twitter or flickr APIs, unfortunately i couldnt desing a clear way to solve my problem.. I tried ASIHTTPRequest but i faced some problems with setting up the Libraries. And if i'm not wrong, ASIHTTPRequest is not such a good idea in i-OS 5 (i m not sure about this).. Anyway, from this point can anyone please help me about how to parse the JSON above?
Finaly i figured out, i have done everything before, i just realized that..
for example when i tried:
NSString*key1=[ result objectForKey:#"key" ];
NSString *kAndVal=[result objectForKey:#"button"];
NSLog(#"\n%# : %#", key1, kAndVal);
i got the key and button values above.. I hope this answer will save lots of newbies like me out of trouble..
You should parse your JSON anwer using a JSON parser. iOS 5 has its own JSON parser. In case you want to support iOS 4 check out JSONKIT https://github.com/johnezang/JSONKit