microsoftgraph / msgraph-sdk-objc

Microsoft Graph SDK for Objective-C
MIT License
37 stars 21 forks source link

MSGraphContact - missing in action? #37

Closed SteveDCronin closed 4 years ago

SteveDCronin commented 5 years ago

I'm using CocoaPods: ... pod 'MSGraphClientSDK' pod 'MSGraphMSALAuthProvider' ... running 'pod install' yields: ... Installing MSAL (0.5.0) Installing MSGraphClientSDK (1.0.0) Installing MSGraphMSALAuthProvider (0.2.0) ... There are no conflicts noted!

The online docs here: https://docs.microsoft.com/en-us/graph/api/user-post-contacts?view=graph-rest-1.0&tabs=objc

have a code sample for ObjectiveC which includes this statement: ... MSGraphContact *contact = [[MSGraphContact alloc] init];

My application has:

import <MSGraphClientSDK/MSGraphClientSDK.h>

...

I get an 'undeclared identifier' compiler error for 'MSGraphContact' I cannot find any instance of the MSGraphContact class in the Pods/MSGraphClientSDK/**

Please clarify what I am missing or what I am misunderstanding!

MIchaelMainer commented 5 years ago

I believe you need to install the MSGraphClientModels pod file. Let me know if that works.

SteveDCronin commented 5 years ago

Michael;

Hey Thanks - that got the files.... Can you point out where I missed this in the documentation? How did you figure this out?

When I examine the MSGraphContact class it is not clear how I would assign 'Categories' to this class. Please clarify how that is accomplished using this new class?

Steve

MIchaelMainer commented 5 years ago

You didn't miss it - we missed it. I just checked, we don't have it mentioned in the readme. I'll add it to the readme.

Regarding setting Categories, it is an NSArray of strings. The setter is defined here: https://github.com/microsoftgraph/msgraph-sdk-objc-models/blob/master/GeneratedModels/MSGraphOutlookItem.h#L13 .

MIchaelMainer commented 5 years ago

The repo for the models is here: https://github.com/microsoftgraph/msgraph-sdk-objc-models

There are some great resources here to help you: https://developer.microsoft.com/en-us/graph/get-started/ios

SteveDCronin commented 5 years ago

Michael;

Thanks for your help so far! I am continuing to use the code snippet I referred to above. Now that I can build an MSGraphContact I am trying to complete the task per to remainder of the snippet. I am getting an error that does not make sense to me.

It occurs here: contact = [[MSGraphContact alloc] init]; ... NSError error=nil; NSData contactData = [contact getSerializedDataWithError:&error];

There error is: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (MSGraphEmailAddress)'

The contact has a single email address constructed like this: NSMutableArray emailAddressesList = [[NSMutableArray alloc] init]; MSGraphEmailAddress emailAddress = [[MSGraphEmailAddress alloc] init]; [emailAddress setAddress:@"tim@apple.com"]; [emailAddress setName:@"Tim Cook"]; [emailAddressesList addObject: emailAddress]; [contact setEmailAddresses:emailAddressesList];

Can you clarify 2 things: 1) why the method terminates rather than report the error? 2) what am I doing wrong in constructing the MSGraphEmailAddress

I am opening this same issue in 'models' GitHub you mention above just to make sure....

MIchaelMainer commented 5 years ago

@SteveDCronin I see nothing wrong with how you created the contact.

Does NSJSONSerialization.isValidJSONObject(emailAddress) return true?

https://github.com/microsoftgraph/msgraph-sdk-objc-models/blob/af0518ec31da0727b739db9d1b578ffc7f7197d7/BaseModels/MSObject.m#L53

SteveDCronin commented 5 years ago

From code: NSDictionary *emailDict; emailAddress = [[MSGraphEmailAddress alloc] init]; [emailAddress setAddress:@"tim@apple.com"]; [emailAddress setName:@"Tim Cook"]; NSLog(@"%s emailAddress: %@",func,emailAddress.name); NSLog(@"%s emailAddress: %@",func,emailAddress.address); if ([NSJSONSerialization isValidJSONObject:emailAddress]) { NSLog(@"%s isValid: %@",func,emailAddress); } else { NSLog(@"%s isNOTValid: %@",func,emailAddress); } emailDict=[emailAddress getDictionary]; if ([NSJSONSerialization isValidJSONObject:emailDict]) { NSLog(@"%s emailDict isValid",func); } else { NSLog(@"%s emailDict isNOTValid",func); }

From log: 2019-09-10 19:27:29.036826-0700 XYZ] emailAddress: Tim Cook 2019-09-10 19:27:29.892016-0700 XYZ] emailAddress: tim@apple.com 2019-09-10 19:27:44.159134-0700 XYZ] isNOTValid: <MSGraphEmailAddress: 0x2835ae940> 2019-09-10 20:00:47.931312-0700 XYZ] emailDict isValid

Huh?

SteveDCronin commented 5 years ago

Michael;

You responded to my question about assigning Categories and the online document mentioned above delineates 'categories' as string collection. I have successfully used the HTTP post mechanism to work around the issues in using the MSGraphContact class. In the initial testing the assignment of a category seems to be accepted but when I view the newly created contact @ 'https://outlook.live.com/people/' I don't see any category assigned (nor do I see any online means of assigning 'category'...... Is there a limitation with categories that I overlooked somewhere?

MIchaelMainer commented 5 years ago

@SteveDCronin I'm not familiar with the categories feature. I suggest that you first search on Stack Overflow for the [microsoft-graph] tag and categories. There is already a lot of Q&A for this subject.

Otherwise, post your question to Stack Overflow with the microsoft-graph tag.

I do not understand why the MSGraphEmailAddress is not a valid JSON object. We will need to check whether other complex types are valid JSON objects.

SteveDCronin commented 5 years ago

I can tell you that MSGraphPhysicalAddress also fails with the same error. For now I have given up on using the MSGraph ObjectiveC model objects.... I have succeeded in creating a contact just using JSON formatted text & HTTP Post