Google+ check-in location in ios - iphone

I want to implement location check-in feature in ios. My application is using google+ ios sdk. The problem which I am facing is that after I have implemented google+ check-in feature then that post is not being displayed on my google+ account.
The technique which I have tried and implemented is written below.
-(IBAction)checkIn
{
GTMOAuth2Authentication *auth = [GPPSignIn sharedInstance].authentication;
GTLServicePlus* plusService = [[GTLServicePlus alloc] init] ;
plusService.retryEnabled = YES;
[plusService setAuthorizer:auth];
GTLPlusMoment *moment = [[GTLPlusMoment alloc] init];
moment.type = #"http://schemas.google.com/CheckInActivity";
GTLPlusItemScope *target = [[GTLPlusItemScope alloc] init] ;
target.url =#"https://developers.google.com/+/plugins/snippet/examples/place";
moment.target = target;
GTLQueryPlus *query =
[GTLQueryPlus queryForMomentsInsertWithObject:moment
userId:#"me"
collection:kGTLPlusCollectionVault];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
id object,
NSError *error) {
if (error) {
GTMLoggerError(#"Error: %#", error);
NSString *failure =
[NSString stringWithFormat:#"Status: Error: %#", error];
NSLog(#"%#",failure);
} else {
NSString *result = #"CheckedIn Saved in Google+";
NSLog(#"%#",result);
}
}];
}
Can any one please help me out. Is this the right way of implementing location check-in feature of google+ or is there any other method for it?

The method you're using is writing an "app activity" to Google+, which stores a "moment" in the user's app activity vault. As noted on https://developers.google.com/+/mobile/ios/app-activities these moments are not directly visible on the user's stream, although users may choose to share them to the stream if they wish.
To see the moments that have been shared, you will need to use the desktop app. Your profile has a list of apps that are using the Google+ Sign-In and you can view, share, and delete the activities for each of these apps. The mobile Google+ clients don't let you view the activities yet.

Related

show app name on facebook share iPhone

I am using facebook.framework i want to share image using native facebook Dialog of iOS 6.0
I can share image but i want to show my app name.... like currently it showing via ios....
I6+
+65 want to show app name..Like via xyz... I am using below code.....
- (IBAction)publishButtonAction:(id)sender {
// Try and present the iOS Share Sheet
[FBDialogs
presentOSIntegratedShareDialogModallyFrom:self
initialText:#"" image:[UIImage imageNamed:#"iossdk_logo.png"]
url:[NSURL URLWithString:#"https://developers.facebook.com/ios"]
handler:^(FBOSIntegratedShareDialogResult result, NSError *error) {
NSString *alertText = #"";
if ([[error userInfo][FBErrorDialogReasonKey]
isEqualToString:FBErrorDialogNotSupported]) {
alertText = #"iOS Share Sheet not supported.";
} else if (error) {
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
} else if (result == FBNativeDialogResultSucceeded) {
alertText = #"Posted successfully.";
}
if (![alertText isEqualToString:#""]) {
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}];
}
Unfortunately, you can't show your App Name if you want to use Facebook.framework and the iOS 6 default share dialog.
The only way to achieve this is to register an app on Facebook Developers and handle every connection/request using their iOS SDK.
Facebook.framework is the most straightforward way to deal with Facebook APIs but you have to renounce to your app name. Otherwise, you can take the harder way and build your app from scratch so you'll be able to show your app name. More info here: Facebook Share Dialog.

iOS 6 SDK SLRequest returning '400'

Let me make this clear. I am NOT using the Facebook SDK. I'm using iOS SDK's Social.framework, and ACAccountStore to access Facebook accounts, and post with it/them.
I use the same code to post on Twitter. It works 100%. But for some reason regardless of what I do for Facebook integration, I get a "400" error when I try to post.
My method is:
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// Specify App ID and permissions
NSDictionary *options = #{ ACFacebookAppIdKey: #"MY_APP_ID",ACFacebookPermissionsKey: #[#"publish_stream", #"publish_actions"],ACFacebookAudienceKey: ACFacebookAudienceFriends };
[account requestAccessToAccountsWithType:facebookAccountType options:options
completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSDictionary *parameters = #{#"message": string999};
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/feed"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:feedURL
parameters:parameters];
acct.accountType = facebookAccountType;
// Post the request
[feedRequest setAccount:acct];
// Block handler to manage the response
[feedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (granted && error == nil) {
} else {
NSLog(#"Facebook response, HTTP response: %i %#", [urlResponse statusCode], [error description]);
[self closeShareMenu];
}
}];
}
}
I don't know where I'm going wrong! It's so annoying! I've set up my app correctly in Facebook Developers and all! Please help -_-'
Following up to the chat session held between #fguchelaar and yours truly yesterday; I was able to ascertain the following solution for this issue.
Add the following in your iOS completion handler:
NSString *temp = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];
NSLog(temp);
//'data' is your 'responseData' (or another object name) that you declare in your completion handler.
This will allow you to see the exact cause of the issue printed to the Debug Console. Now depending on the issue presented, you'll need to grab a Facebook account from the Array of Accounts generated when you call this handler in the iPhone SDK. Not at any prior stage whatsoever, as the Access Token will likely expire and give you this '400' error.
In my case; the error printed was: error:{'400' A valid access token is required… which vastly annoyed me as my prior method to access and check the current Twitter account was working perfectly. And my theory was that it should work just as well for Facebook. Why should the access token be instantaneously revoked if I'm grabbing the account a split second before?
The way I solved my issue (depending on the reason for your error the answer can vary) was to use a for loop to check the newly created array of accounts, with the sole purpose of finding the account there with the same identifier string as the one I saved into NSData/NSKeyedArchiver.
for(ACAccount *a in arrayOfAccounts) {
if([a.identifier isEqualToString:storedAccount.identifier]) {
//set the account to be used
accountToBeUsed = a;
//don't forget to break the For loop once you have your result.
break;
} else {
//This else{} block is not strictly necessary, but here you could set an account if no account was found with a matching identifier.
}
}
For it to work, it's recommended to declare an ACAccount object in your View Controller's .h file, add a #property and #synthesize it, so it can be assigned within the for loop and used after the break; statement.
This effectively solved my whole issue with the '400' error. It was inexplicably frustrating for about six hours of my day, so I hope that my explanation helps anybody who happens to stumble across this issue, and my question here on Stack Overflow :)
Regards,
cocotutch

Confused using UIActivityViewController

Can you help me to understand when should I use UIActivityViewController. I have a button which shares common information about my app (something like "I like this app" with link and image). My old code was:
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:picture forKey:#"picture"];
[params setObject:link forKey:#"link"];
[params setObject:#"I like MY app!" forKey:#"caption"];
[params setObject:#"I am now using MY iPhone app." forKey:#"description"];
[params setObject:linkToTheIcon forKey:#"icon"];
[params setObject:#"including link" forKey:#"type"];
[[FacebookConnection instance] feedLink:params andDelegate:self];
Now I want to use UIActivityViewController but I'm a bit confused how to pass all those parameters to it. Or should I do things in other way?
ADDED:
So I understood that I need silent posting procedure.
Could you please guide me through silent post procedure using iOS 6 features (e.d. using built-in FB account). For now I can't understand how to check if FB account exists on the device and if it is not how to prompt to create it? There is a method in ACAccount store class – requestAccessToAccountsWithType:options:completion: to access an account. But If an account does not exists it returns an error. Many thanks in advance.
In your situation it seems obvious that you should not use UIActivityViewController because you want to post on Facebook and not on twitter or anywhere else, right?
Firstly you need to get access to user's account. You do this like this:
-(void)requestBasicPermissionsForFacebookAccount {
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = #[#"email"];
NSDictionary * options = #{ACFacebookAppIdKey : kFacebookAppId, ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceEveryone};
FacebookAccountManager * fbMgr = [[FacebookAccountManager alloc] init];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
fbMgr.account = [accounts lastObject];
fbMgr.isBasicPermissionsGranted = YES;
[self.accountManagers addObject:fbMgr];
NSLog(#"granted!");
}
else {
fbMgr.account = nil;
fbMgr.isBasicPermissionsGranted = NO;
switch ([error code]) {
case 1:
[self showErrorAlertWithMessage:#"Unknown error occured, try again later!"];
break;
case 3:
[self showErrorAlertWithMessage:#"Authentication failed, try again later!"];
break;
case 6:
[self showErrorAlertWithMessage:#"Facebook account does not exists. Please create it in Settings and come back!"];
break;
case 7:
[self showErrorAlertWithMessage:#"Permission request failed. You won't be able to share information to Facebook"];
break;
default:
break;
}
NSLog(#"error is: %#", error);
}
}];
}
If an account does not exists you should prompt user to create it in settings and then try to to obtain basic permissions again.
You first need to subclass UIActivity.
Then you need to override certain methods, including activityImage for setting the icon and performActivity for performing the action .
If instead of performing the action silently, you first need further user interaction and info for your custom activity (e.g., like the Twitter post for the standard UIActivity), you should override activityViewController rather than performActivity.
After you have subclassed UIActivity (as, e.g, MyActivity), you should create an instance of MyActivity and make it an element of the applicationActivities array that you pass to initWithActivityItems:applicationActivities:.
Have a look at the documentation for UIActivity for exactly what you need to override when subclassing and for icon requirements.
Hope this helps a little

iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" error

I'm trying to perform a simple posting procedure:
- (IBAction)directPostClick:(id)sender {
self.statusLabel.text = #"Waiting for authorization...";
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = #[#"publish_stream", #"user_checkins", #"publish_checkins", #"user_likes", #"user_videos"];
NSDictionary * dict = #{ACFacebookAppIdKey : #"My app id here", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
__block NSString * statusText = nil;
if (granted) {
statusText = #"Logged in";
NSArray * accounts = [self.accountStore accountsWithAccountType:facebookAccountType];
self.facebookAccount = [accounts lastObject];
NSLog(#"account is: %#", self.facebookAccount);
self.statusLabel.text = statusText;
[self postToFeed];
}
else {
self.statusLabel.text = #"Login failed";
NSLog(#"error is: %#", error);
}
}];
}
EDITED:
The problem is that when I click on alertView's OK button (don't allow doesn't work either) nothing happens! - This behavoir now changed with this
iOS 6 Facebook posting procedure ends up with "remote_app_id does not match stored id" So instead of just "nothing happens" I've got an error
"The Facebook server could not fulfill this access request: remote_app_id does not match stored id"
So , it seems that alert view's click handler doing nothing, my completionHandler is never called.
I do have the similar problem already: iOS 6 Social integration - go to settings issue
And I think that it is the same problem here. What do you guys think about it?
P.S.
I'm running on MAC mini, OS X 10.8.1 with latest xcode 4.5 (4G182) and using iPhone 6.0 simulator.
ADDED:
By the Bjorn's request adding the postToFeed method although it is never called:
- (void)postToFeed {
NSDictionary * parameters = #{#"message" : #"Hello world!"};
NSURL * feedUrl = [NSURL URLWithString:#"https://graph.facebook.com/me/feed"];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedUrl parameters:parameters];
request.account = self.facebookAccount;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = #"Posted!";
});
}];
}
I also experienced some difficulties when working with the Accounts Framework and the Facebook integration. Here is what I've learned and how I got it working.
1. Make sure you've setup your App on Facebook correctly
You need to set how your App integrates with Facebook to Native iOS App and enter the Bundle ID of your App into the designated field. (Edit: Note that bundle IDs are case sensitive) You can set the iTunes ID to 0 for now. Enable Facebook Login and set the App Type in the advanced settings tab to Native/Desktop.
Also set App Secret in Client to No.
If one or more of these options are not set correctly it's very likely you get the error The Facebook server could not fulfill this access request: remote_app_id does not match stored id.
(Edit: You also have to ensure the sandbox is disabled.)
2. Installing the Facebook App for the first time
When first installing an App via the native Facebook integration on iOS (and Mac OS X too), you must ask for a basic read permission only! Nothing else as email, user_birthday and user_location is allowed here. Using user_about_me, which is also a basic read permission according to the Facebook documentation, does not work. This is pretty confusing if you previously worked with the Facebook JavaScript SDK or the Facebook PHP SDK, because it asks for the basic permissions by default without you having to do something. Facebook also updated their documentation with a short step-by-step guide on how to use the new Facebook SDK on iOS 6.
3. Requesting additional permissions
It's important to know, that you may not ask for read and write permissions at the same time. That's also something experienced Facebook SDK developers may find confusing. Requesting the read_stream permission along with the publish_stream permission will make the request fail, resulting in the error An app may not aks for read and write permissions at the same time.
As Facebook does not really distinguish between read/write permissions in the Permission Reference, you must identify write permissions by yourself. They're usually prefixed with manage_*, publish_*, create_* or suffixed by *_management.
Facebook does also not recommend to ask for additional permissions immediately after getting basic permissions. The documentation says "You are now required to request read and publish permission separately (and in that order). Most likely, you will request the read permissions for personalization when the app starts and the user first logs in. Later, if appropriate, your app can request publish permissions when it intends to post data to Facebook. [...] Asking for the two types separately also greatly improves the chances that users will grant the publish permissions, since your app will only seek them at the time it needs them, most likely when the user has a stronger intent.".
4. Sample Code
The following sample code should work on iOS and Mac OS X:
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// At first, we only ask for the basic read permission
NSArray * permissions = #[#"email"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"My app id here", ACFacebookAppIdKey, permissions, ACFacebookPermissionsKey, ACFacebookAudienceOnlyMe, ACFacebookAudienceKey, nil];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if (granted && error == nil) {
/**
* The user granted us the basic read permission.
* Now we can ask for more permissions
**/
NSArray *readPermissions = #[#"read_stream", #"read_friendlists"];
[dict setObject:readPermissions forKey: ACFacebookPermissionsKey];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if(granted && error == nil) {
/**
* We now should have some read permission
* Now we may ask for write permissions or
* do something else.
**/
} else {
NSLog(#"error is: %#",[error description]);
}
}];
} else {
NSLog(#"error is: %#",[error description]);
}
}];
make sure sandbox mode is not activated if you are trying to access facebook account from application for non developer users.

Invalid Facebook access token

I am developing an application which posts videos to Facebook.
I have registered this app on Facebook, received APIkey, APIsecret, the app successfully passes authentication and receives the access token. Here is my code for authentication:
m_Facebook = [[Facebook alloc] init];
[m_Facebook logout:self];
m_FacebookUploader = [[FBVideoUpload alloc]init];
NSArray *permissions = [NSArray arrayWithObjects:#"publish_stream", #"offline_access",#"read_stream",nil];
m_Facebook.forceOldStyleAuth = YES;
[m_Facebook authorize:kApiKey permissions:permissions delegate:self];
However when trying to upload a video, the class FBVideoUpload tries to separate the access token into several parts:
- (NSString*) sessionID
{
NSArray *components = [accessToken componentsSeparatedByString:#"|"];
NSLog(#"components: %#", components);
return [components count] < 2 ? nil : [components objectAtIndex:1];
}
According to http://developers.facebook.com/docs/authentication/ the access token should contain several componenets, separated by "|", but the one I receive at authentication does not contain several components separated by a "|". The access_token I receive looks as follows:
AAA*GXJapke*BAGRlZC7aBLhiZB*MUEV*AAF6*ZBhZBw*0ER1M*vkXlRUZCwO*czfgs*wHbnA*BcTU*VrPZC*Yw3p*JmCIMZ*xSnCP*GqPRWZALgZDZ*
(I replaced some symbols with "*")
Here is my code for uploading the video:
[m_FacebookUploader setApiKey:kApiKey];
[m_FacebookUploader setAccessToken:m_Facebook.accessToken];
[m_FacebookUploader setAppSecret:kApiSecret];
[m_FacebookUploader startUploadWithURL:url params:params delegate:self];
I receive an error here:
if ([self sessionID] == nil) {
NSLog(#"Unable to retrieve session key from the access token.");
return;
}
Which not surprising since sessionID really returns nil.
Whatever library you're using to do that video upload is using some outdated logic to handle uploads. That whole method where it breaks apart the session key doesn't need to exist. Just use the access token you get back from FB with your video upload request. Also, be sure you're using our latest SDK https://github.com/facebook/facebook-ios-sdk