send message API error - api

I am sending send message request with XML bodyfrom my iphone application
<mailbox-item><recipients><recipient><person path='/people/93619553' /></recipient><recipient><person path='/people/116008244' /></recipient><recipient><person path='/people/96885725' /></recipient></recipients><subject>Message from butterfli</subject><body>Aasd</body></mailbox-item>
But getting this error
++ LinkedIn engine reports failure for connection 3CD3052A-7061-4EA0-8863-5584270B9177
The operation couldn’t be completed. (HTTP error 404.)
Code is
- (RDLinkedInConnectionID *)sendMessage:(NSDictionary *)shareDict {
NSURL* url = [NSURL URLWithString:[kAPIBaseURL stringByAppendingString:#"/v1/people/~/mailbox"]];
NSString *xmlStr = #"<mailbox-item><recipients>";
NSArray *toIdArray = [[shareDict objectForKey:#"privacy"] componentsSeparatedByString:#","];
for (int l=0; l<[toIdArray count]; l++) {
xmlStr = [xmlStr stringByAppendingString:[NSString stringWithFormat:#"<recipient><person path='/people/%#' /></recipient>",
[toIdArray objectAtIndex:l]]];
}
xmlStr = [xmlStr stringByAppendingString:[NSString stringWithFormat:#"</recipients><subject>%#</subject><body>%#</body></mailbox-item>",
#"Message from butterfli",[shareDict objectForKey:#"text_message"]]];
[NSString stringWithFormat:#"<share><comment>%#</comment><content><submitted-url>%#</submitted-url></content><visibility><code>anyone</code></visibility></share>",
[shareDict objectForKey:#"link_msg"],[shareDict objectForKey:#"link"]];
NSData *body = [xmlStr dataUsingEncoding:NSUTF8StringEncoding];
NSLog(#"xmlStr..%#",xmlStr);
return [self sendAPIRequestWithURL:url HTTPMethod:#"POST" body:body];
}
Amit Battan

its not a closed issue before it...
But now the solution is
its done...
Before it I am hardcoded the user id which is shown in the URL of user profile on Web.
But its working ok with id of user which is coming through API ..
But not getting why linkedin user different ids??
as
LinkedIn use unique user IDs for each user/application combination to protect user's privacy. Only the application which originally requested (and got) authentication from the member can use that token to retrieve further information.
http://developer.linkedin.com/thread/3044

Related

Google Drive API for Objective-C return some file not all

I'm implementing Google Drive Api for my mac application using Google API Client for REST Library below,
- (void)fetchFileList {
_fileList = nil;
_fileListFetchError = nil;
GTLRDriveService *service = self.service;
GTLRDriveQuery_FilesList *query = [GTLRDriveQuery_FilesList query];
// Because GTLRDrive_FileList is derived from GTLCollectionObject and the service
// property shouldFetchNextPages is enabled, this may do multiple fetches to
// retrieve all items in the file list.
query.fields = #"kind,nextPageToken,files(mimeType,id,kind,name,webViewLink,thumbnailLink,trashed)";
_fileListTicket = [service executeQuery:query
completionHandler:^(GTLRServiceTicket *callbackTicket,
GTLRDrive_FileList *fileList,
NSError *callbackError) {
// Callback
_fileList = fileList;
_fileListFetchError = callbackError;
_fileListTicket = nil;
NSLog(#"%#", fileList);
}];
}
Here the return value
GTLRDrive_FileList 0x6080002404e0: {kind:"drive#fileList" files:[5]}
There are 7 items on my drive but it returns only 5 items?
It may have something to do with your nextPageToken. It returned only the result of a certain page, not all of them.
Check this docs:
Sometimes a query may return a large number of results, which are
returned one page at a time. When a result object includes a
nextPageToken string, you can execute the query again; supply the
returned token as the pageToken property of the new query, fetching
the next set of results. You can repeat this until you reach the last
page, which will not inlude a nextPageToken string.
GTLServiceDrive *drive = ...;
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = search;
[drive executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *fileList,
NSError *error) {
if (error == nil) {
NSLog(#"Have results");
// Iterate over fileList.files array
} else {
NSLog(#"An error occurred: %#", error);
}
}];
Try the Drive sample from the iOS Quickstart on how to fetch Files properly. Here's a snippet:
/ Construct a query to get names and IDs of 10 files using the Google Drive API.
- (void)fetchFiles {
self.output.text = #"Getting files...";
GTLQueryDrive *query =
[GTLQueryDrive queryForFilesList];
query.pageSize = 10;
query.fields = #"nextPageToken, files(id, name)";
[self.service executeQuery:query
delegate:self
didFinishSelector:#selector(displayResultWithTicket:finishedWithObject:error:)];
}

Persisting bookmark in core-data

I have an OSX application that is supposed to have a list of files from anywhere in the user's disk.
The first version of the app saves the path to these files in a core-data model.
However, if the file is moved or renamed, the tool loses its purpose and the app can crash.
So I decided to use bookmarks. It seems to be working, but every time I try to recover the data, I get the old path of the files. Why is that? What am I missing?
My core-data entity uses a binary data field to persist the bookmark.
The bookmark itself is done like this:
NSData * bookmark = [filePath bookmarkDataWithOptions:NSURLBookmarkCreationMinimalBookmark
includingResourceValuesForKeys:NULL
relativeToURL:NULL
error:NULL];
And on loading the application, I have a loop to iterate all the table and recover the bookmark like this:
while (object = [rowEnumerator nextObject]) {
NSError * error = noErr;
NSURL * bookmark = [NSURL URLByResolvingBookmarkData:[object fileBookmark]
options:NSURLBookmarkResolutionWithoutUI
relativeToURL:NULL
bookmarkDataIsStale:NO
error:&error];
if (error != noErr)
DDLogCError(#"%#", [error description]);
DDLogCInfo(#"File Path: %#", [bookmark fileReferenceURL]);
}
If I rename the file, the path is null. I see no difference between storing this NSData object and a string with the path. So I am obviously missing something.
Edit:
I also often get an error like this: CFURLSetTemporaryResourcePropertyForKey failed because it was passed this URL which has no scheme.
I appreciate any help, thanks!
I can't find any issues in my code, so I changed it.
After looking for the reason of the "no scheme" message, I came to the conclusion some third-party application is required for this code to work, and that's undesirable.
I am now using aliases. This is how I create them:
FSRef fsFile, fsOriginal;
AliasHandle aliasHandle;
NSString * fileOriginalPath = [[filePath absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
OSStatus status = FSPathMakeRef((unsigned char*)[fileOriginalPath cStringUsingEncoding: NSUTF8StringEncoding], &fsOriginal, NULL);
status = FSPathMakeRef((unsigned char*)[fileOriginalPath cStringUsingEncoding: NSUTF8StringEncoding], &fsFile, NULL);
OSErr err = FSNewAlias(&fsOriginal, &fsFile, &aliasHandle);
NSData * aliasData = [NSData dataWithBytes: *aliasHandle length: GetAliasSize(aliasHandle)];
And now I recover the path like this:
while (object = [rowEnumerator nextObject]) {
NSData * aliasData = [object fileBookmark];
NSUInteger aliasLen = [aliasData length];
if (aliasLen > 0) {
FSRef fsFile, fsOriginal;
AliasHandle aliasHandle;
OSErr err = PtrToHand([aliasData bytes], (Handle*)&aliasHandle, aliasLen);
Boolean changed;
err = FSResolveAlias(&fsOriginal, aliasHandle, &fsFile, &changed);
if (err == noErr) {
char pathC[2*1024];
OSStatus status = FSRefMakePath(&fsFile, (UInt8*) &pathC, sizeof(pathC));
NSAssert(status == 0, #"FSRefMakePath failed");
NSLog(#"%#", [NSString stringWithCString: pathC encoding: NSUTF8StringEncoding]);
} else {
NSLog(#"The file disappeared!");
}
} else {
NSLog(#"CardCollectionUserDefault was zero length");
}
}
However, I am still curious on why my previous code failed. I appreciate any thoughts on that. Thanks!

I'm trying to search an NSArray for a string, and none of my researched methods are working

I'm using Parse and I'm retrieving a class from the data browser titled: "usernames".
I get all the objects in the class, and store them in an array. I then want to search the array for a username, so that the user may login. I will do the same for the password. Here's my code:
- (IBAction)login:(id)sender
{
if ([usernameLogin.stringValue isEqualTo:#""] || [passwordLogin.stringValue isEqualTo:#""]) {
NSBeginAlertSheet(#"Error", #"OK", nil, nil, self.window, self, #selector(sheetDidEnd:resultCode:contextInfo:), NULL, NULL, #"Please fill in all fields.");
}
/* retrieve user from parse db */
PFQuery *usernameQuery = [PFQuery queryWithClassName:#"usernames"];
[usernameQuery findObjectsInBackgroundWithBlock:^(NSArray *usernames, NSError *error) {
NSString *userString = [NSString stringWithFormat:#"%#", usernameLogin.stringValue];
NSLog(#"USERS:\n %#", usernames);
int i;
for (i = 0; i < [usernames count]; i++) {
NSString *userFind = [usernames objectAtIndex:i];
if ([userString isEqualToString:userFind]) {
NSLog(#"FOUND!!!");
}
}
/*
if ([usernames indexOfObject:usernameLogin.stringValue]) {
NSLog(#"User: '%#' was found successfully!", usernameLogin.stringValue);
} else {
NSLog(#"User: '%#' doesn't exist in database, or password was incorrect!", usernameLogin.stringValue);
}
*/
}];
gameCont = [[CSGameController alloc] initWithWindowNibName:#"CSGameController"];
[gameCont showWindow:self];
[gameCont.window makeKeyAndOrderFront:nil];
_window.isVisible = false;
}
Can anyone explain what I'm doing wrong? I'm searching the database to see if the entered user exists. I setup a test user, and it still says it doesn't exist. Thanks so much!
Added:
int i;
for (i = 0; i < [usernames count]; i++) {
NSString *userFind = [usernames objectAtIndex:i];
NSLog(#"UserFind class = %#, value = %#", [userFind class], userFind);
}
Output:
[2438:303] UserFind class = PFObject, value = <usernames:kx7aG2xfkX:(null)> {
username = ryan;
}
It seems you're trying to do a lot of things here that just don't make sense. Please consider reading the Parse iOS Guide. All PFQueries return PFObjects. PFObjects are in many ways like NSDictionaries; they are a single record in a database and can be fetched or stored.
A PFQuery always returns one or more PFObjects. A PFQuery's results should almost always be scopable to be immediately useful. In this example, the equals condition could have been articulated with -[PFQuery whereKey:equalTo:]. It is much faster to let Parse do the search for you. This also lets you create UI powered by the query's results via PFQueryTableViewController.
Finally, please please please don't make your own login code. Your current code is easily hacked to not only allow anyone to log in as anyone, but to learn anyone's password as well. Use the built-in PFUser class for user accounts. It handles secure login, offline caching of credentials, password resets, email verification, you can let users log in with their Facebook or twitter accounts in addition to username/password, and Parse has built-in view controllers for logging in and creating accounts of PFUsers. PFUsers are also the way to secure your data; a PFACL is an Access Control List that lets you decide which PFUsers can read or write data.
The wrong thing here that you are trying to use isEqualToString: with userFind, which is PFObject.
Try comparing with its username property:
...
for (PFObject *aUsername in usernames)
{
NSString *userFind = [aUsername objectForKey:#"username"];
if ([userString isEqualToString:userFind]) {
NSLog(#"FOUND!!!");
}
}
Problem solved: I used Parse's User class. They have pre-existing methods for registering users, like I was trying to do here in my own classes. Their methods for registering are:
PFUser *user = [PFUser user];
user.email = emailField.stringValue;
user.username = usernameField.stringValue;
user.password = passwordField.stringValue;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

Parsing Push notification iOS

trying ot parse the push I geting with my app.
but i get some problems here:
NSString *resourcePath = [[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey] objectForKey:#"aps"];
NSLog(#"resourcePath: %#", resourcePath);
NSLog
{
alert = cb;
badge = 1;
sound = default;
url = cxb; }
I NSLog it as String... how to get the URL?
Thank you!
Its a dictionary Object. Get object for url key. Like this:
NSString *resourcePathURL = [[[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey] objectForKey:#"aps"] objectForKey:#"url"] ;
NSLog(#"URL : %#",resourcePathURL);

dataWithContentsOfURL - What is expected from the server?

I am trying to create NSData with the contents of an URL:
NSString *theUrl = [NSString stringWithString:#"http://127.0.0.1:8090"];
NSError *connectionError = nil;
NSData *inData = [NSData dataWithContentsOfURL:[NSURL URLWithString:theUrl] options:NSDataReadingUncached error:&connectionError];
NSInteger code = [connectionError code];
if (code != 0)
{
NSString *locDesc = [NSString stringWithString:[connectionError localizedDescription]];
NSString *locFail = [NSString stringWithString:[connectionError localizedFailureReason]];
NSLog(#"Error: %d %# %#", code, locDesc, locFail);
}
else if ([inData length] == 0)
{
NSLog(#"No data");
}
I have a super simple Java http server running on the local host that returns Hello World to a client:
DataOutputStream os = new DataOutputStream(s.getOutputStream()); // s is the socket
os.writeBytes(new String("Hello World\0"));
os.flush();
os.close();
s.close();
When pointing Google Chrome to http://127.0.0.1:8090 it displays Hello World as expected so data is sent back. When I run the objective-c code the inData is empty (0x0, data length is 0), and the error code is 0 so I don't have an error to inspect. If I change theUrl to "http://www.google.com" it seems works fine as the data length becomes > 0.
So my question is why inData is empty when I go the to local http-server. Does the stream have to be terminated with a specific data sequence?
Is the server outputting an HTTP status code like it's supposed to? If the response doesn't contain a 200 status indicating that the request was completed successfully, that might be causing dataWithContentsOfURL:options:error: to fail.
A little more context would be useful, but a wild guess is that your "super simple" HTTP server does not send any headers or not the ones expected by NSURL.
Have you tried curl -i http://127.0.0.1:8090 to see what the output actually looks like?