how to fix -[__NSCFString gtm_stringByUnescapingFromURLArgument] in google+ authentication - iphone

I am trying to create an application that retrieves the current user's email id, user id, user name from his google+ account. The part of the code is as follows,
- (IBAction)googleSigninBtnTapped:(id)sender
{
[GPPSignInButton class];
[GPPSignIn sharedInstance].clientID =[NSString stringWithFormat:#"MY APP ID"];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.delegate = self;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.shouldFetchGoogleUserID = YES;
signIn.actions = [NSArray arrayWithObjects:
#"http://schemas.google.com/AddActivity",
#"http://schemas.google.com/BuyActivity",
#"http://schemas.google.com/CheckInActivity",
#"http://schemas.google.com/CommentActivity",
#"http://schemas.google.com/CreateActivity",
#"http://schemas.google.com/ListenActivity",
#"http://schemas.google.com/ReserveActivity",
#"http://schemas.google.com/ReviewActivity",
nil];
[signIn trySilentAuthentication];
}
(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError )error
{
if (error)
{
NSLog(#"Status: Authentication error: %#", error);
}
else
{
NSLog(#"Status: Authenticated");
NSLog(#"Email: %#",[GPPSignIn sharedInstance].authentication.userEmail);
GTLServicePlus plusService = [[[GTLServicePlus alloc] init] autorelease];
plusService.retryEnabled = YES;
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:#"me"];
[plusService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
{
if (error)
{
GTMLoggerError(#"Error: %#", error);
}
else
{
[person retain];
NSLog(#"%#", person.displayName);
NSLog(#"%#", person.identifier);
}
}];
}
}
But when i am trying to execute my app, it gets crashed, saying that
'-[__NSCFString gtm_stringByUnescapingFromURLArgument]: unrecognized selector sent to instance 0x9e435b0'
Can anybody help me on this...!!!
Thanks In Advance!!!

Yep, you need the -ObjC linker flag in, it's not finding one of the categories from the GoogleOpenSource framework.
See Step 3 in the setup guide: https://developers.google.com/+/mobile/ios/getting-started#step_3_initialize_the_google_client
Basically, in Other Linker Flags, add -ObjC (capitalisation is important, note!). Also make sure you have included both GooglePlus and GoogleOpenSource frameworks in your project.

Add with _objc the other flag called -lc++

Related

Error 204, The Request Did not Return any Content While Posting data to Twitter

I tried to post from twitter but it not posting the comments. It display an error 204 , in the facebook the same data is successfully posted but in the twitter i got an error can any one have an idea How to solve it
-(void)postDataOnTwitterMethod{
if ([[FHSTwitterEngine sharedEngine]isAuthorized]) {
NSData *dataFromPath = UIImageJPEGRepresentation(cameraImage,1.0);
number = (arc4random()%10000)+1; //Generates Number from 1 to 10000.
RndNo = [NSString stringWithFormat:#"%i", number];
NSLog(#" ITEM %#",RndNo);
NSString *avalabelDate = [NSString stringWithFormat:#"%#_%#",[CommonMethods getCurrentDateAndTime],self.AvailableTillTextField.text];
NSString *theWholeString = [NSString stringWithFormat:#"Item No: %#\nItemName: %#\nItemCost: %#\nAvailableTill: %#\nCategory: %#\nDescription: %#",RndNo,self.NameTextField.text,self.PriceTextField.text,avalabelDate,self.ListTypeTextField.text,self.DecTextView.text];
dispatch_async(GCDBackgroundThread, ^{
#autoreleasepool {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSError *returnCode = [[FHSTwitterEngine sharedEngine]postTweet:theWholeString withImageData:dataFromPath];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *title = nil;
NSString *message = nil;
if (returnCode) {
title = [NSString stringWithFormat:#"Error %d",returnCode.code];
message = returnCode.localizedDescription;
} else {
title = #"Tweet Posted";
}
dispatch_sync(GCDMainThread, ^{
#autoreleasepool {
UIAlertView *av = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
}
});
}
});
}
else{
[[FHSTwitterEngine sharedEngine]showOAuthLoginControllerFromViewController:self withCompletion:^(BOOL success) {
NSLog(success?#"L0L success":#"O noes!!! Loggen faylur!!!");
}];
}
}
Your comments made me smile.
I believe it's an HTML error. It means the data was received and understood but you shouldn't expect a return. In other words, it's void. At least that's what I can see with a quick look around your code and my minimal understanding of Twitter API.
Now i am able to send the String but cant able to send the Image using this method
NSError *returnCode = [[FHSTwitterEngine sharedEngine]postTweet:theWholeString withImageData:imageData];
FHSTwitterEngine has some known bugs, and the problem is now fixed, see below:
Getting error while posting image using FHSTwitterEngine
compress the existing image with this code and you will get images posted.
NSData *data = UIImageJPEGRepresentation(imageView.image, 0.6);

Why can't I authenticate to Facebook Chat in my iOS application?

I have been scouring the internet trying to find a solution to this problem. I understand the basic idea on how it is supposed to work, but I can't get the implementation to work and I can't find any decent examples to help me. So far I have successfully been able to log in a user using the iOS 6 authentication mechanism, but I cannot figure out how to authenticate a user to the Jabber server from there. Here is what I have:
After the user has logged in connect is called
-(void)connect
{
[self setupStream];
NSError *error = nil;
[_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
NSLog(#"%#", error);
[NSString stringWithFormat:#"%#", self];
}
-(void)newSetupStream
{
_xmppStream = [[XMPPStream alloc] initWithFacebookAppId:#"611051652253156"];
#if !TARGET_IPHONE_SIMULATOR
{
xmppStream.enableBackgroundingOnSocket = YES;
}
#endif
_xmppReconnect = [[XMPPReconnect alloc] init];
_xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];
_xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:_xmppRosterStorage];
_xmppRoster.autoFetchRoster = YES;
_xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;
_xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
_xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:_xmppvCardStorage];
_xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:_xmppvCardTempModule];
_xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
_xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:_xmppCapabilitiesStorage];
_xmppCapabilities.autoFetchHashedCapabilities = YES;
_xmppCapabilities.autoFetchNonHashedCapabilities = NO;
[_xmppReconnect activate:_xmppStream];
[_xmppRoster activate:_xmppStream];
[_xmppvCardTempModule activate:_xmppStream];
[_xmppvCardAvatarModule activate:_xmppStream];
[_xmppCapabilities activate:_xmppStream];
[_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[_xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
No matter what I try it always returns the same error: Error Domain=XMPPStreamErrorDomain Code=4 "The server does not support X-FACEBOOK-PLATFORM authentication."
I am not incredibly familiar with either XMPP or the Facebook API so I'm sure there is something simple I am missing, but I have been working on this forever and been unable to make any progress. Any ideas?
I found my answer. In case anyone else runs into this same problem: I never actually told my XMPPStream to connect. I had tried all of the connect methods before, but they never worked. I now realize that I simply did not wait for them to finish connecting. Here is what I ended up changing:
NSError *error;
NSError *err;
[_xmppStream connectWithTimeout:10.00 error:&err];
[_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
while (error)
{
sleep(1);
[_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
}
I realize that it's not the most elegant solution, but it works.
make sure you use chat.facebook.com or facebook.com as the host name.
You must also open session with xmpp_login permission.
For me the above host name worked 100% fine

Post on personal Facebook wall using ios sdk and tag multiple friends at once..?

I am trying to post a message on my wall and wanted to tag multiple users at a time in this post. I tried the various options on the FB post page but couldn't do it. May be I am not doing it right. Any help is appreciated and this is how I am doing it...
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test 2",#"message",
#"100004311843201,1039844409", #"to",
nil];
[self.appDelegate.facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
I have also tried message_tags but that doesn't seem to work as well.
You would need to use Open Graph to tag people with a message. The me/feed Graph API endpoint doesn't support this.
Mentions Tagging
https://developers.facebook.com/docs/technical-guides/opengraph/mention-tagging/
Action Tagging:
https://developers.facebook.com/docs/technical-guides/opengraph/publish-action/
You can take a look at the Scrumptious sample app that comes included with the latest Facebook SDK for iOS to see how to do this.
To tag a friend in ur fb status ..you need "facebook id" of your friend by using FBFriendPickerViewController and "place id" using FBPlacePickerViewController. Following code will help you.
NSString *apiPath = nil;
apiPath = #"me/feed";
if(![self.selectedPlaceID isEqualToString:#""]) {
[params setObject:_selectedPlaceID forKey:#"place"];
}
NSString *tag = nil;
if(mSelectedFriends != nil){
for (NSDictionary *user in mSelectedFriends) {
tag = [[NSString alloc] initWithFormat:#"%#",[user objectForKey:#"id"] ];
[tags addObject:tag];
}
NSString *friendIdsSeparation=[tags componentsJoinedByString:#","];
NSString *friendIds = [[NSString alloc] initWithFormat:#"[%#]",friendIdsSeparation ];
[params setObject:friendIds forKey:#"tags"];
}
FBRequest *request = [[[FBRequest alloc] initWithSession:_fbSession graphPath:apiPath parameters:params HTTPMethod:#"POST"] autorelease];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[SVProgressHUD dismiss];
if (error) {
NSLog(#"Error ===== %#",error.description);
if (_delegate != nil) {
[_delegate facebookConnectFail:error requestType:FBRequestTypePostOnWall];
}else{
NSLog(#"Error ===== %#",error.description);
}
}else{
if (_delegate != nil) {
[_delegate faceboookConnectSuccess:self requestType:FBRequestTypePostOnWall];
}
}
If you followed the tutorial on how to setup Open Graph for iOS, you can do something like this if you use the friendsPickerController:
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
//Iterate over selected friends
if ([friendPickerController.selection count] > 0) {
NSMutableArray *temp = [NSMutableArray new];
for (id<FBGraphUser> user in self.friendPickerController.selection) {
NSLog(#"Friend selected: %#", user.name);
[temp addObject:[NSString stringWithFormat:#"%#", user.id]];
}
[action setTags:temp];
}
Basically, you can set an array of friend's ids on the "tags" property on an action

fetching GDataFeedPhotoAlbum returns wrong object type

I'm trying to implement fetching an picasa web album on iphone, have downloaded the code and example from google.code but have run into a problem where fetching an album feed returns me feed with wrong object types - GDataEntryBase instead of GDataEntryPhoto.
Here's the code I'm using:
First I'm calling this to get all my albums:
- (void)fetchAllAlbums
{
NSLog(#"Fetching all albums");
//request albums
GDataServiceTicket *ticket;
NSURL *feedURL = [GDataServiceGooglePhotos photoFeedURLForUserID:myemail
albumID:nil
albumName:nil
photoID:nil
kind:nil
access:nil];
ticket = [_GooglePhotoService fetchFeedWithURL:feedURL
delegate:self
didFinishSelector:#selector(albumListFetchTicket:finishedWithFeed:error:)];
[self set_AlbumFetchTicket: ticket];
}
Now, in the callback I call to get all the photos of each returned album:
- (void)albumListFetchTicket:(GDataServiceTicket *)ticket
finishedWithFeed:(GDataFeedPhotoUser *)feed
error:(NSError *)error
{
[self set_UserAlbumFeed: feed];
[self set_AlbumFetchError:error];
[self set_AlbumFetchTicket:nil];
if (error == nil) {
NSLog(#"Got albums!");
for (GDataEntryPhotoAlbum * albumEntry in _UserAlbumFeed)
{
NSLog(#"Album Title: %#", [[albumEntry title] stringValue]);
{
NSLog(#"Fetching photos!");
[self set_AlbumPhotosFeed:nil];
[self set_PhotosFetchError:nil];
[self set_PhotosFetchTicket:nil];
GDataServiceTicket *ticket;
ticket = [_GooglePhotoService fetchFeedWithURL: [[albumEntry feedLink] URL]
delegate: self
didFinishSelector: #selector(photosTicket:finishedWithFeed:error:)];
[self set_PhotosFetchTicket:ticket];
}
}
}
}
and this is the callback for each album photo feed fetch:
// photo list fetch callback
- (void)photosTicket:(GDataServiceTicket *)ticket
finishedWithFeed:(GDataFeedPhotoAlbum *)feed
error:(NSError *)error
{
//tell me what class you are
NSLog(#"Feed class: %#", NSStringFromClass([feed class]));
[self set_AlbumPhotosFeed: feed];
[self set_PhotosFetchError: error];
[self set_PhotosFetchTicket: ticket];
if (error == nil)
{
NSLog(#"Got Photos!");
for (GDataEntryPhoto * photo in feed)
{
NSLog(#"Title: %#", [[photo title] stringValue]);
//tell me what class you are
NSLog(#"%#", NSStringFromClass([photo class]));
//NSArray * thumbnails = [[photo mediaGroup] mediaThumbnails];
//NSLog(#"thumbnails count: %d", [thumbnails count]);
//NSLog(#"Photo thumnail url: %#", [[thumbnails objectAtIndex:0] URLString]);
}
}
}
The trouble is that the entries in the feed in the last callback are not of type GDataEntryPhoto, just the base GDataEntryBase - and so trying to access their thumbnail urls will crash the app.
The code is copied from google's cocoa (non-touch) example, and there it works - the feed returned is populated with the GDateEntryPhoto objects.
Any help would be greatly appreciated.
Add -ObjC -all_load to Other Linker Flags in your xcodeproject, then add SystemConfiguration.framework, CFNetwork.framework and Security.framework to Build Phases -> Link Library With Binaries.

GData Picasa Photo Album iPhone

I was hoping someone could help me with this problem. I am trying to access a Picasa Web Album from my iphone application. I have used GData previously with Google Calendar and getting events and the data related to them before, so I set up my methods in a similar fashion. I however am getting an error that is telling me the following
serviceBase:<GDataServiceGooglePhotos: 0x4d4e6d0> objectFetcher:<GDataHTTPFetcher: 0xbaa35c0> failedWithStatus:400 data:Too many results requested
I am think that I have narrowed down the problem that I am having has something to do with the ticket that I am using, in the following line
ticket = [service fetchFeedWithURL:[NSURL URLWithString:kGDataGooglePhotosAllFeed]
delegate:self
didFinishSelector:#selector(photosListTicket:finishedWithFeed:error:)];
I however am unable to get past this problem. Does anyone have a suggestion to get past this problem. Am I doing something wrong?
My full code for the retrieval of the pictures is shown below. Anywhere that says picAlbum, that is a predefined NSArray to hold the information.
- (GDataServiceGooglePhotos *)photoService {
static GDataServiceGooglePhotos* service = nil;
if (!service) {
service = [[GDataServiceGooglePhotos alloc] init];
[service setShouldCacheDatedData:YES];
[service setServiceShouldFollowNextLinks:YES];
}
[service setUserCredentialsWithUsername:#"username"
password:#"password"];
return service;
}
-(void)loadGooglePhotos {
[self fetchAllPhotos];
}
-(void)fetchAllPhotos {
NSLog(#"In fetchAllPhotos");
GDataServiceGooglePhotos *service = [self photoService];
GDataServiceTicket *ticket;
ticket = [service fetchFeedWithURL:[NSURL URLWithString:kGDataGooglePhotosKindAlbum]
delegate:self
didFinishSelector:#selector(photosListTicket:finishedWithFeed:error:)];
}
- (void)photosListTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedPhotoAlbum *)feed error:(NSError *)error {
NSLog(#"In photosListTicket");
NSArray *photos = [feed entries];
if ([photos count] != 0){
self.picAlbum = [photos objectAtIndex:0];
NSLog(#"fetching photos");
[self fetchPhotos];
}
else {
NSLog(#"User has no photos...");
}
}
- (void)fetchPhotos {
NSLog(#"In fetchPhotos");
if (self.picAlbum) {
NSURL *feedURL = [[self.picAlbum alternateLink] URL];
if (feedURL) {
NSLog(feedURL);
GDataQueryGooglePhotos *query = [GDataQueryGooglePhotos photoQueryWithFeedURL:feedURL];
[query setMaxResults:1000];
GDataServiceGooglePhotos *service = [self photoService];
GDataServiceTicket *ticket;
ticket = [service fetchFeedWithQuery:query delegate:self didFinishSelector:#selector(photosEventsTicket:finishedWithFeed:error:)];
}
}
}
- (void)photosEventsTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedPhotoAlbum *)feed error:(NSError *)error {
NSLog(#"In photosEventsTicket");
NSArray *photos = [feed entries];
NSLog([NSString stringWithFormat:#"%i",[photos count]]);
}
Thanks in advance for any information or help that you can provide.
If the server says "Too many results requested" that's a clue that the max results query parameter is too big.
The fetches in the code snippet do not appear functional. Neither kGDataGooglePhotosKindAlbum nor an album's alternateLink would be URLs for feeds.