I coding a iOS app using O365-iOS-Connect to connect my app to Office 365. My app can sign in to 365 account. But i can not find some docs how to Fetch/Create calender.
O365-iOS-Connect
Thanks and sorry for my bad english.
Steps to fetch outlook calendars in iOS are:
I use MSGraph SDK & Azure AD v2.0 endpoint(for personal login)
Note: You must know how to install pods and check this link for details: https://graph.microsoft.io/en-us/
Steps:
Register your iOS application on Microsoft Application Registration Portal and it will give you a client-id
Install the following pods :
pod 'MSGraphSDK-NXOAuth2Adapter'
pod 'MSGraphSDK'
Go to your ViewController and define :
#property (strong, nonatomic) MSGraphClient *client;
NSString *clientId = #"<you_clientId>"; // GLOBAL to the class
Now import these files as:
#import <MSGraphSDK/MSGraphSDK.h>
#import <MSGraphSDK-NXOAuth2Adapter/MSGraphSDKNXOAuth2.h>
5.On your button click: First you have use your client-id and define your permissions in the scope as:
[NXOAuth2AuthenticationProvider setClientId:clientId
scopes:#[#"https://graph.microsoft.com/Files.ReadWrite",
#"https://graph.microsoft.com/Calendars.ReadWrite"]];
Now you have to authenticate with your login details and Microsoft login screen automatically opens up:
[[NXOAuth2AuthenticationProvider sharedAuthProvider] loginWithViewController:nil completion:^(NSError *error) {
if (!error) {
[MSGraphClient setAuthenticationProvider:[NXOAuth2AuthenticationProvider sharedAuthProvider]];
self.client = [MSGraphClient client];
//Authenticated successfully
} }];
If there is no error, then error is nil and it will logged in successfully.
Now we can use different APIs using MSGraphClient and for calendars list:
[[[[self.client me] calendars] request] getWithCompletion:^(MSCollection *response, MSGraphUserCalendarsCollectionRequest *nextRequest, NSError *error) {
NSArray *calendars = response.value;
// Here we are getting calendars
}];
Now, get calendars button action look like this:
- (IBAction)getCalendars:(id)sender {
[NXOAuth2AuthenticationProvider setClientId:clientId
scopes:#[#"https://graph.microsoft.com/Files.ReadWrite",
#"https://graph.microsoft.com/Calendars.ReadWrite"]];
[[NXOAuth2AuthenticationProvider sharedAuthProvider] loginWithViewController:nil completion:^(NSError *error) {
if (!error) {
[MSGraphClient setAuthenticationProvider:[NXOAuth2AuthenticationProvider sharedAuthProvider]];
self.client = [MSGraphClient client];
[[[[self.client me] calendars] request] getWithCompletion:^(MSCollection *response, MSGraphUserCalendarsCollectionRequest *nextRequest, NSError *error) {
NSArray *calendars = response.value;
// Here we are getting calendars
}];
} }];
}
we have a couple options in our GitHub code samples that might be of assistance.
One is called O365-iOS- Snippets: https://github.com/OfficeDev/O365-iOS-Snippets. The O365 iOS Snippets project shows you how to do basic operations against the Calendar, Contacts, Mail, and Files service endpoints in Office 365.
For Microsoft Graph, we've also created an iOS snippets project for that - https://github.com/OfficeDev/O365-iOS-Microsoft-Graph-Snippets. This sample shows how to use Microsoft Graph to send email, manage groups, and perform other activities with Office 365 data.
Hope this helps!
Freya H, The Office Newsroom
Related
I am working on ios application where I have to implement facebook publish/share feature. what I have done for sharing is
1: if user is not logged in, I am checking with this
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded||FBSession.activeSession.state == FBSessionStateOpen) {
//NSLog(#"Open");
//Set already opened session to FBSession
[FBSession setActiveSession:appDelegate.session];
//if user logged in already, perform sharing on fb
[self sharePostOnFb];
}else{
//if user is not logged in
[self openFbLogin];
}
-(void)openFbLogin
{
[FBSession openActiveSessionWithReadPermissions:#[#"public_profile", #"email",#"publish_actions"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
// Retrieve the app delegate
//AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
//[appDelegate sessionStateChanged:session state:state error:error];
if (state == FBSessionStateOpen) {
NSLog(#"opened");
[self sharePostOnFb];
}
}];
}
-(void)sharePostOnFb
{
NSString *strBznsName = [[[Global sharedInstance]getBznsInfo] objectForKey:#"name"];
NSString *strUserReceive = [NSString stringWithFormat:#"%# %# received %#.",[[[Global sharedInstance]getUserData] objectForKey:#"firstname"],[[[Global sharedInstance]getUserData] objectForKey:#"lastname"],dataStampDeal.strDealTerms];
NSString *urlLogoBkString= #URL_BZNSImgPath;
NSURL *urlLogoBkImage = [NSURL URLWithString:[NSString stringWithFormat:#"%#/%#",urlLogoBkString,[[[Global sharedInstance]getBznsInfo] objectForKey:#"logo" ]]];
NSString *StrUrl = [NSString stringWithFormat:#"%#",urlLogoBkImage];
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
strBznsName, #"name",
#"Powered By Anyloyalty", #"caption",
strUserReceive, #"description",
StrUrl, #"picture",
nil];
// Make the request
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Link posted successfully to Facebook
NSLog(#"result: %#", result);
strFbPostId = [result valueForKey:#"id"];
NSLog(#"post id: %#", strFbPostId);
//[self WebServiceHandler:NO];
//[appDelegate startanimation];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description );
NSDictionary *errorInformation = [[[[error userInfo] objectForKey:#"com.facebook.sdk:ParsedJSONResponseKey"]
objectForKey:#"body"]
objectForKey:#"error"];
//NSLog(#"%#", errorInformation );
//__block NSString *alertText = #"Your action will not be published to Facebook.";
__block NSString *alertText = [errorInformation valueForKey:#"message"];
[[[UIAlertView alloc] initWithTitle:#"error"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
}
}];
}
facebook login (-(void)openFbLogin()) is opening web dialog. After successfully logged in. I am sharing post ( -(void)sharePostOnFb()) on fb and I am getting error
"(#200) The user hasn't authorized the application to perform this action"
For publishing/sharing I have to get approval for "publish_actions" permission from FB. I have submitted my application to FB app developer center. I am getting this message.
"Your app must not use a Facebook Web Dialog. Utilize our native Facebook Login SDK for iOS, so that users do not need to login twice."
so Now I want to "what is native Facebook Login SDK for iOS"? and how can I integrate that with my app?
The native Facebook login is nothing but using the iOS FB framework and create login using that. It is clearly mentioned on the developers.facebook.com how to login using there framework. You can also see the samples provided by them for login.
What this actually does is that , it check if the user has a Facebook application installed in the device and is user logged in to the Facebook app. If user is already logged in then user won't be asked to log in again. If user isn't logged in then they will be redirected to safari where they will have to log in to FB.
Its quite simple to integrate. Its well explained.
Facebook clearly says,
All iOS and Android apps should use their SDK's for iOS and Android for requesting permissions. Other apps should use their JavaScript for requesting permissions wherever possible.
Native applications on iOS and Android especially should use their SDK flows as they are optimized and work robustly across various types of devices without any manual adjustment.
In particular, their native SDKs let people who are already logged in to their Facebook app grant permissions without having to log in to their Facebook accounts again. This will result in far better conversion than not using our SDK and rendering our login dialogs inside web views embedded within your native app since the web view will not have any Facebook session data initially and will require people to login to their Facebook account.
Please note: if you are using Apple's Social framework, you may continue to do so, but ensure that if the user is not using the iOS integration, that your app falls back to the Facebook SDK for iOS. This can create more work than necessary, though, so we highly recommend using their SDK instead.
Here are the SDK implementation details:Facebook Login SDK for iOS
I am using this code below, which uses the parse sdk:
[PFFacebookUtils initializeFacebook];
[FBSession.activeSession requestNewReadPermissions:#[#"user_photos"] completionHandler:^(FBSession *session, NSError *error) {
if (!error) {FBRequestConnection *connection = [[FBRequestConnection alloc] init];
FBRequest *request = [[FBRequest alloc] initWithSession:[FBSession activeSession]
graphPath:[NSString stringWithFormat:#"me/photos"]];
[connection addRequest:request completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {}];
[connection start];
This all works fine for me it downloads all the most recent photos. But for anyone else, who has logged in via Facebook on the app the result returns:
{
data = (
)
}
Why am i, the developer, the only one who is able to access his photos? Is there a setting in the app settings on Facebook?
From v2.0 onwards, the permissions other than public_profile, email and the user_friends need to the submitted for review before you can make your app live; until then, only the testers/admin/developers of the app will be able to test app with those permissions.
See here for details on the Login Review.
yes there is,
You have to go on you facebook developer account -> go on the application -> add a contact email.
After that go to status & review -> and set Do you want to make this app and all its live features available to the general public? to yes.
Now it should work
I'm trying to insert a "Moment" into a user's Google+ account, using the google-api-objectivec-client library. I think have the authentication process working properly. It's primarily the same way I have YouTube authentication set up, but with the correct scope and keychain name. However, when I try to run the query to insert the moment I get the following error:
Error Domain=com.google.GTLJSONRPCErrorDomain Code=401 "The operation
couldn’t be completed. (Unauthorized)"
After looking at Google's documentation more carefully (here) I found the following comment:
When authenticating for moments.insert, you must include the data-requestvisibleactions
parameter to specify which types of App Activities your application will write.
Google has several examples of how to do this with other programming languages, but they don't have any examples for the objective-c library, and the objective-c project doesn't contain any examples of how to do this either.
I know that there's another authentication method, using the GPPSignIn button, which has a way to set the actions. However, my application is using multiple other Google API clients (YouTube, YouTube Analytics, and URL Shortener). Mixing the GoogleOpenSource.framework with the other Objective-C libraries causes a conflict. So, I need to use the GTMOAuth2ViewControllerTouch class.
My Authentication Code
GTMOAuth2ViewControllerTouch *viewController =
[GTMOAuth2ViewControllerTouch controllerWithScope:kGTLAuthScopePlusLogin
clientID:kGoogleApiClientId
clientSecret:kGoogleApiClientSecret
keychainItemName:kGooglePlusKeychainName
completionHandler:^(GTMOAuth2ViewControllerTouch *viewController, GTMOAuth2Authentication *auth, NSError *error) {
if (error)
NSLog(#"Error: %#", error.description);
else
app.googlePlusService.authorizer = auth; //this sets a property of my app delegate, to be used elsewhere in the application
}];
[self.navigationController pushViewController:viewController animated:YES];
The code I'm using to insert the "Moment"
NSString *shareUrl = "http://www.google.com"; //just for this example
GTLPlusMoment *moment = [[GTLPlusMoment alloc] init];
moment.type = #"http://schemas.google.com/AddActivity";
GTLPlusItemScope *target = [[GTLPlusItemScope alloc] init];
target.url = shareUrl;
moment.target = target;
GTLQueryPlus *query =
[GTLQueryPlus queryForMomentsInsertWithObject:moment
userId:#"me"
collection:kGTLPlusCollectionVault];
[app.googlePlusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
id object,
NSError *error) {
if (error) {
NSLog(#"Got bad response from plus.moments.insert: %#", error);
} else {
NSLog(#"Moment inserted: %#",moment.identifier);
}
}];
Has anyone out there successfully found the place to add the data-requestvisibleactions parameter to either the authentication call or queryForMomentsInsertWithObject method to allow them to execute the moments.insert action without receiving an error?
Thanks!
You can add data-requestvisibleactions using Java Script code in Authentication. Once you authorized with java script, it will be authorized for all types of insert moments. There is no method in Objective c for adding data-requestvisibleactions in your code. Only the option is possible through Java Script.
For More derails Refer THIS
I'm trying to use iOS Social.framework to share to Facebook. However, most users will not have Facebook setup in Settings>Facebook so therefore Facebook doesn't show up when you bring up a UIActivityViewController, it just isn't listed. (See UIActivity with no settings for Facebook or just google "facebook doesn't show in UIActivityViewController," there's plenty of people trying to solve this problem.)
Our app already uses the Facebook SDK so I can get at the Facebook account info, so I thought I would just get the info and then save the info in Settings>Facebook. Here's my code. (Which I got from When do we use saveAccount:(ACAccount *)account of ACAccountStore class? and iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert)
- (void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret {
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
//We start creating an account by creating the credentials object
ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
ACAccountType *acctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:acctType];
//Here we assign credentials and now can save account
newAccount.credential = credential;
NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
[VVEnvironment stringForKey:kVVEnvironmentKeyFacebookAppID], (NSString *)ACFacebookAppIdKey,
[NSArray arrayWithObject:#"basic_info"], (NSString *)ACFacebookPermissionsKey,
ACFacebookAudienceEveryone, (NSString *)ACFacebookAudienceKey,
nil];
[_accountStore requestAccessToAccountsWithType:acctType options:options completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
[self.accountStore saveAccount:newAccount withCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"the account was saved!");
}
else {
if ([error code] == ACErrorPermissionDenied) {
NSLog(#"Got a ACErrorPermissionDenied, the account was not saved!");
}
NSLog(#"the account was not saved! %d, %#", [error code], error);
}
}];
}
else {
NSLog(#"ERR: %# ",error);
}
}];
}
I added the call to requestAccessToAccountsWithType there because without I was getting a ACErrorPermissionDenied back from saveAccount. When I run this I do see my app slide briefly aside for the Facebook dialog (if I delete my app on Facebook's website it does bring up the full dialog asking me for permissions which I grant.)
The problem is that granted is always NO, so I never get a chance to save the account. What am I missing here?
I am running this on a real device that has the Facebook App installed and setup.
I'd appreciate any help on this, thanks!
There is no solution available for this. iOS native facebook applications are not allowed to write or save account to ACAccountStore. It only allow to access account from the ACAccountStore. iOS only allow to store 1 facebook account at a time. Try to do these steps you will understand this easily,
Add a facebook account to settings App and try to get permission to access it. It will grand permission.
Remove account and try to get the permission it will deny access.
Add a facebook account and get access and try to save new account to ACAccountStore, It will say that Native applications are not allowed to save account to ACAccountStore.
The proposed solution is, Add the account to settings App and login with it and Share using Social framework or presentOSIntegratedDialog.
So when I am logged in to ios's facebook integration, my code works great. I get an active access token with permissions to read and write, and I have actually written to people's walls and whatnot from the app. However, when my app uses safari to authenticate people's login credentials, there is the common error: "An active access token must be used to query information about the current user."
What I don't understand is why I can only get my access code from the ios facebook integration. Anyways, my relevant code below is implemented by the current view controller when it loads:
if (![FBSession activeSession].isOpen) {
[self openSession];
}
my method openSession is defined as follows
- (void)openSession
{
//create the permissions array
NSArray *permissions =
[NSArray arrayWithObjects:#"email", #"basic_info", nil];
[FBSession openActiveSessionWithReadPermissions: permissions
allowLoginUI:YES
completionHandler: ^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(#"\n\nopenSession called error = %#\n\n\n",error);
}];
}
I then go on to continue in the viewDidLoadMethod
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error)
{
NSLog(#"error requestion connection: %#",error);
}];
I look forward to the response. Thanks in advance.
Using Facebook SDK.
NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
If you prefer dot syntax,
NSString *fbAccessToken = [FBSession activeSession].accessTokenData.accessToken;`
I hope , it will work for u