Pinterest error invalid sdk client key ios - ios

I am implementing Pinterest in my app.My code is as follows:
pinterest = [[Pinterest alloc]initWithClientId:#"Myapp_ClientID"];
NSURL *imageURL = [NSURL URLWithString:#"http://7-themes.com"];
NSURL *sourceURL = [NSURL URLWithString:#"http://7-themes.com/data_images/out/42/6914793-tropical-beach-images.jpg"];
[pinterest createPinWithImageURL:sourceURL
sourceURL:sourceURL
description:#"Pinning from Pin It Demo"];
I registered app and got client id which I put in my code but when run on device it always give me error invalid client id

You are giving the Client key wrong. (Which should be obvious). Most likely this question will be taken off but let me help you anyways:
pinterest = [[Pinterest alloc]initWithClientId:#"Myapp_ClientID"];
On the above line you are giving the client key wrong. Sdk client keys are long and with alternating Alpha numeric characters to enhance security. What you are doing is, you are passing it a string which holds the value Myapp_ClientID. So your operation is aborted.
If you have declared Myapp_ClientID as a constant or it is a variable of corresponding type, then simply use this line:
pinterest = [[Pinterest alloc]initWithClientId:Myapp_ClientID];
Else provide the correct client key like:
pinterest = [[Pinterest alloc]initWithClientId:#"Your client key here"];

Related

Google Direction API returns error in iOS

Am using following google direction url
https://maps.googleapis.com/maps/api/directions/json?origin=12.976600,77.599300&destination=12.991491,77.715347&client=gme-company&signature=Fwelfejfcb4bbb3hj5bb=
and its not giving any result
in browser its showing
Unable to authenticate the request. Provided 'signature' is not valid for the provided client ID, or the provided 'client' is not valid.
The signature was checked against the URL: /maps/api/directions/json?origin=12.976600,77.599300&destination=12.991491,77.715347&client=gme-company
If this does not match the URL you requested, please ensure that your request is URL encoded correctly. Learn more: https://developers.google.com/maps/documentation/business/webservices/auth
my method is this
- (void) estimateETAWithWithOrigin:(CLLocationCoordinate2D)origin destination:(CLLocationCoordinate2D)destination onSuccess:(DirectionsCompletionBlock) completionBlock {
NSString *baseUrl = [NSString stringWithFormat:#"%#?origin=%f,%f&destination=%f,%f&client=%#&signature=%#",
GOOGLE_DIRECTIONS_API,
origin.latitude,
origin.longitude,
destination.latitude,
destination.longitude,
CLIENTID,CRYPTO_KEY];
baseUrl = [baseUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"%#",baseUrl);
.....
}
Pls help
You can find information on how to use digital signatures in the developers documentation
You even have a place there to test your signature.
The code for signing a request in Objective C can be found on the google maps github repo

How do I use an iOS app's bundle identifier to 'authorize' upload to Google Cloud Storage?

Our service is using Google App Engine as our backend, and we're now implementing an upload-function for images etc.
Using the answers from several different questions here on stack, I have made it working, but not completely as I want. We are not using the built-in OAuth etc, and for now we want the storage to be public, but not entirely public. We would like to limit it to users of our own app (I.E no authentication). In the Cloud-console we can create an API-key for iOS. When doing this, we copy the API-key to the app, and pass it along with every upload-request. This is currently working, when the bucket-permission is set to allUsers - WRITE
However, inside the API-key, we can supply our app's own Bundle Identifier, so that, supposedly, only requests from our app is allowed. (App Store ID/URL is also permitted, apparently).
Adding this bundle-id does nothing as long as the bucket has the permission allUsers - WRITE. If I change the bundle-id to not match the actual bundle-id, it still works. So which permission should it use for the bucket to make the bundle-id in the API-key apply? And what should be sent along in the upload-code on iOS (acl?)?.
If I remove the allUsers-permission, and use something else, I get this error when trying to upload:
{message:"There is a per-IP or per-Referer restriction configured
on your API key and the request does not match these
restrictions. Please use the Google Developers Console
to update your API key configuration if request from this
IP or referer should be allowed." data:[1] code:403}}
This is how I'm using it right now (though I have tried several different things, all picked up from different questions/answers):
GTLServiceStorage *serv = [[GTLServiceStorage alloc] init];
serv.additionalHTTPHeaders = [NSDictionary dictionaryWithObjectsAndKeys:
#"[my project id]", #"x-goog-project-id",
#"application/json-rpc", #"Content-Type",
#"application/json-rpc", #"Accept", nil];
serv.APIKey = #"[my iOS API key, gotten from console, (linked to bundle-id?)]";
serv.retryEnabled = YES;
GTLStorageBucket *bucket = [[GTLStorageBucket alloc] init];
bucket.name = #"[my bucket]";
GTLUploadParameters *params = [GTLUploadParameters uploadParametersWithFileHandle:fileHandle MIMEType:#"image/jpeg"];
GTLStorageObject *storageObject = [[GTLStorageObject alloc] init];
storageObject.name = #"testFile.jpg";
//I have no idea what I'm doing with the following stuff, but I've tried several things:
GTLStorageObjectAccessControl *objAccessControl
= [GTLStorageObjectAccessControl new];
//This is working
objAccessControl.entity = #"allUsers";
objAccessControl.email = #"[my app-id]#project.gserviceaccount.com";
objAccessControl.role = #"OWNER";
//If I try this instead, it is not working.
//objAccessControl.domain = #"[my app-id].apps.googleusercontent.com";
//objAccessControl.role = #"WRITER";
//Probably because it's bullshit, I have no idea what I'm doing.
storageObject.acl = #[objAccessControl];
[...] //Bucket and upload and stuff. It seems like it's the ACL-thing above that's not working..
It seems like I have to connect the permissions on the bucket to the iOS API Key somehow, but I don't know if it's even possible.
What I want: All users to be able to use the cloud, given that they are requesting it from my iOS app.
As this question never got an answer I'll add one here, based on the information currently in the post.
The reason you got the error 'There is a per-IP or per-Referer restriction..' when calling the GCS API with the iOS API Key is simply because the GCS API doesn't work with API Keys for private data, only Bearer Tokens (ie. using OAuth). There isn't anything you could have done to make the API Key work with the GCS API directly with private data. The reason it worked when you had 'allUsers - WRITE' set as the ACL is simply because that ACL allows public access.
To access the private data without user intervention requires a Service Account, however the Google APIs Objective-C Client only supports OAuth2 Client IDs. The rationale being that Service Accounts are intended for server-side authentication only. Using a Service Account in a client would involve distributing the private key along with the app, which could easily be compromised. For reference, here's a sample of how you might authorize the GCS service using OAuth:
NSString *keychainItemName = #"My App";
NSString *clientID = <your-client-id>;
NSString *clientSecret = <your-client-secret>;
// How to check for existing credentials in the keychain
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2WindowController authForGoogleFromKeychainForName:kKeychainItemName
clientID:clientID
clientSecret:clientSecret];
...
// How to set up a window controller for sign-in
NSBundle *frameworkBundle = [NSBundle bundleForClass:[GTMOAuth2WindowController class]];
GTMOAuth2WindowController *windowController;
windowController = [GTMOAuth2WindowController controllerWithScope:kGTLAuthScopeStorageDevstorageFullControl
clientID:clientID
clientSecret:clientSecret
keychainItemName:kKeychainItemName
resourceBundle:frameworkBundle];
[windowController signInSheetModalForWindow:[self window]
completionHandler:^(GTMOAuth2Authentication *auth,
NSError *error) {
if (error == nil) {
self.storageService.authorizer = auth;
}
}];
...
// Initialize service with auth
GTLServiceStorage *serv = [[GTLServiceStorage alloc] init];
serv.authorizer = auth;
All of this was taken from the storage sample on the google-api-objectivec-client GitHub page, so you can refer to it for a complete example with context.
This still leaves the question of how to implement access to GCS from iOS without user authorization. The short answer to this is that the iOS Key can be used to restrict access to your own backend API hosted on Google Cloud Endpoints, and that backend application can authorize against GCS using a Service Account (usually the Application Default Service Account). The Cloud Storage Client Library Examples page has samples using the default credentials for different languages.
Further details on how to implement an Endpoints API for this purpose are probably getting outside of the scope of this question, but this should serve as a good starting point.

Error code 2500 when requesting facebook picture

I am using the social framework and the accounts framework to access facebook from my app. In one line of code I do:
NSURL *meInfo = [NSURL URLWithString:#"https://graph.facebook.com/me"];
Which is successful. I get a json object with me data which I can then use in my app. Confusingly, in the very next block of code, I do this:
NSURL *meInfoPic = [NSURL URLWithString:#"https://graph.facebook.com/me/picture"];
And it fails with:
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
My access token is obviously valid, so I am not sure what is going on. The permissions I am using for both are "publish_stream". Any advice?
My mistake was using /me/ in the picture request URL. Once I replaced that with the user id for the logged in user I got further. So to be clear, I needed to do this:
NSURL *meInfoPic = [NSURL URLWithString:#"https://graph.facebook.com/123456789/picture"];

Facebook permissions to know if a friend uses the same app

I can successfully grab a list of friends with this NSURL, using the permissions "publish_stream":
NSURL *friendsList = [NSURL URLWithString:#"https://graph.facebook.com/me/friends
However, when I try the same thing with an added field, as in this URL:
NSURL *friendsList = [NSURL URLWithString:#"https://graph.facebook.com/me/friends?fields=installed"];
I get an error:
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
So my question is what permissions should I be asking for to make the second URL work?
Bonus question: What URL param do I include to get a small profile pic come back in the same JSON object?
Thanks :)
According to the docs, you it Requires app access_token. However, playing with Graph API Explorer, I could get this info without this permission.
You can take a look at Graph API Explorer to test.
Also, the query on the above link returns the picture field, which will have an URL with the user picture.

ShareKit twitter 403 (unknown error)

I'm using ShareKit to share through FB and twitter. I'm using this code to share to twitter:
- (IBAction)twitterShare:(id)sender {
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:[flexViewController shareURL]];
SHKItem *item = [SHKItem URL:url title:[flexViewController shareText]];
[SHK setRootViewController:self];
// Share the item
[SHKTwitter shareItem:item];
}
I'm getting "403 Forbidden:The server understood the request but is refusing to fulfill it". This always happens if the login view was prompted. If the user was already logged in from an earlier session (the app was closed and reopened), it works correctly.
In this page, it declares that 403 means I have reached a limit, which I don't think it's my case.
https://dev.twitter.com/docs/error-codes-responses
The above code worked correctly last week, but now I'm getting this error.
Ran into the same issue using the old version of ShareKit and was able to solve by editing the Twitter URL in the following section of SHKTwitter.m.
- (void)sendStatus
{
OAMutableURLRequest *oRequest = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1/statuses/update.json"]
The URL was different in the ShareKit 2.0 version.

Resources