Google UrlShortener "ipRefererBlocked" - azure

I have a site hosted on Azure where the calls to the Google UrlShortner API are being blocked. I receive the error:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"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.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"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."
}
}
The API works fine running locally and I have added the ip address to the API project credentials in the developer console. This appears to be an issue with Azure but I don't see where anyone has an answer.
Any suggestions would be great!

I was never able to get this resolved even using a static ip. Work around was tinyUrl. Their api worked flawlessly.

Yes use tiny URL, but not their API. I was never able to get their API to work.
+ (void) shortenLink:(NSString*) link andPerformBlock:(void (^)(NSString*, NSError*))block {
NSURLRequest* shortenedLinkRequest = [LinkShortener createTinyURLShortenerRequest:link];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:shortenedLinkRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString*shortenedLink = #"";
UIAlertView* alert = nil;
if ([data length] > 0 && error == nil) {
NSString* shortenedLink = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
if (block) {
block(shortenedLink, error);
}
}
}
+ (NSURLRequest*) createTinyURLShortenerRequest:(NSString*) link {
NSString* escapedLink = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];;
NSString* tinyURLShortenerURL = [NSString stringWithFormat:#"http://tinyurl.com/api-create.php?url=%#", escapedLink];
NSURL* tinyURLShortenerUrl = [NSURL URLWithString:tinyURLShortenerURL];
NSMutableURLRequest* shortenedLinkRequest = [NSMutableURLRequest requestWithURL:tinyURLShortenerUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:URL_SHORTENER_TIMEOUT];
[shortenedLinkRequest setHTTPMethod:#"GET"];
return shortenedLinkRequest;
}

Related

Can't insert items into table after google authentication in Azure mobile service

I am testing the sample code from Azure Mobile Service site. It's a todo app for iOS. There is a button to create a table for this app in the Azure site. And the app works well.
But after I turned on authentication for google option in the site, I couldn't insert or fetch todos from Azure server. I signed in google through the app and MSClient:loginWithProvider was successful.
[self.todoService.client loginWithProvider:#"google" controller:self animated:YES completion:^(MSUser * _Nullable user, NSError * _Nullable error) {
if (error==nil) {
// obviously successful
NSLog(#"login success %#", user.userId);
}
[self dismissViewControllerAnimated:YES completion:nil];
}];
But whenever I inserted new todo, I got this error.
2016-02-03 00:15:52.311 TryMobileApp[7432:1327892] Error Domain=com.Microsoft.MicrosoftAzureMobile.ErrorDomain Code=-1201 "The server did not return the expected item." UserInfo={NSLocalizedDescription=The server did not return the expected item., com.Microsoft.MicrosoftAzureMobile.ErrorRequestKey=<NSMutableURLRequest: 0x7c258d90> { URL: http://thehome.azurewebsites.net/tables/TodoItem }, com.Microsoft.MicrosoftAzureMobile.ErrorResponseKey=<NSHTTPURLResponse: 0x7ae095e0> { URL: https://thehome.azurewebsites.net/tables/TodoItem } { status code: 200, headers {
"Cache-Control" = "no-cache";
"Content-Encoding" = gzip;
"Content-Length" = 326;
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 02 Feb 2016 16:15:51 GMT";
Etag = "W/\"186-ChUpLnifKBz6ME0BS21A5w\"";
Expires = 0;
Pragma = "no-cache";
Server = "Microsoft-IIS/8.0";
Vary = "Accept-Encoding";
"X-Powered-By" = "Express, ASP.NET";
} }}
If I turned off the authentication option in the Azure site, it worked well again.
Any suggestion?

What Does The Random String In URI Of A PlayList In Spotify Stand For

I am currently integrating Spotify with our music player app. So I visited the official site of Spotify and studied its tutorial.
But when I came across code:
-(void)playUsingSession:(SPTSession *)session
{
// Create a new player if needed
if (self.player == nil)
{
self.player = [[SPTAudioStreamingController alloc] initWithClientId:[SPTAuth defaultInstance].clientID];
}
[self.player loginWithSession:session callback:^(NSError *error)
{
if (error != nil)
{
NSLog(#"*** Logging in got error: %#", error);
return;
}
NSURL *trackURI = [NSURL URLWithString:#"spotify:track:58s6EuEYJdlb0kO7awm3Vp"];
[self.player playURIs:#[ trackURI ] fromIndex:0 callback:^(NSError *error)
{
if (error != nil)
{
NSLog(#"*** Starting playback got error: %#", error);
return;
}
}];
}];
}
I don't know what "58s6EuEYJdlb0kO7awm3Vp" in this line means
NSURL *trackURI = [NSURL URLWithString:#"spotify:track:58s6EuEYJdlb0kO7awm3Vp"];
Is it the id of the track?
Because it is hardcoded, so I don't know how could I request it.
I read the documentation of the APIs especially on the part of SPTPlaylists. But I can't find any explanation of what this string stands for.
Please help me. Thanks in advance!
In the example, 58s6EuEYJdlb0kO7awm3Vp is the Spotify ID for the track, and spotify:track:58s6EuEYJdlb0kO7awm3Vp is its Spotify URI. There is some information in the Spotify Web API User Guide about how identifiers for the Spotify catalog work.
You can use the Spotify desktop client to find out the ID/URI of an album, artist, track or playlist by right-clicking on the header of the view that shows its contents, or you can use the Web API Search endpoint to find out these identifier.
We have just updated the iOS SDK Tutorial to explain better where this ID comes from.

Set Signature Image for Accountless Signer DocuSign

I wanted to use my own logic for requesting signature but after the signature is complete, I want to send the Signed Image (as png) to DocuSign Envelope. I looked at the "Set Signature Image for Accountless Signer" flow and it seemed to be working fine, but the signature image is not embedded in my envelope.
This is what I am doing
Get the Account Information
Create Envelope from a Template as "Created(Draft)" status
Add a recipient
Add a Signature Tab
Update the Envelope Status from "Created" to "Sent"
Set the Signature Image for Recipient.
Everything seems to be working fine without any errors. But I dont see the image. Please let me know if I am doing anything wrong or if you have any examples of Sending Signature Image to Envelopes.
Feel free to contact us for a more creative solution, however the easiest way to get a signature on an iPad is to delegate the signature image collection to DocuSign altogether. here is a way to get a signature on a template (you can also do it with document byte stream). This is taken from the GitHub gist: https://gist.github.com/Ergin008/5645812.
The view for signing can be displayed in a webview in your iOS app.
//
// API Walkthrough 8 - Launch the signing (recipient) view of an envelope in an embedded session
//
// To run this sample:
// 1. Copy the below code into your iOS project
// 2. Enter your email, password, integrator key, name, templateId, and roleName and save
// 3. Run the code
//
- (void)embeddedSigning
{
// Enter your info:
NSString *email = #"<#email#>";
NSString *password = #"<#password#>";
NSString *integratorKey = #"<#integratorKey#>";
NSString *name = #"<#name#>";
// use same name as template role you saved through the Console UI
NSString *roleName = #"<#roleName#>";
// need to login to the console and copy a valid templateId into this string
NSString *templateId = #"<#templateId#>";
///////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves accountId and baseUrl)
///////////////////////////////////////////////////////////////////////////////////////
NSString *loginURL = #"https://demo.docusign.net/restapi/v2/login_information";
NSMutableURLRequest *loginRequest = [[NSMutableURLRequest alloc] init];
[loginRequest setHTTPMethod:#"GET"];
[loginRequest setURL:[NSURL URLWithString:loginURL]];
// set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
NSDictionary *authenticationHeader = #{ #"Username": email, #"Password" : password, #"IntegratorKey" : integratorKey };
// jsonStringFromObject() function defined below...
[loginRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:#"X-DocuSign-Authentication"];
// also set the Content-Type header (other accepted type is application/xml)
[loginRequest setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
//*** make an asynchronous web request
[NSURLConnection sendAsynchronousRequest:loginRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *loginResponse, NSData *loginData, NSError *loginError) {
if (loginError) { // succesful GET returns status 200
NSLog(#"Error sending request %#. Got Response %# Error is: %#", loginRequest, loginResponse, loginError);
return;
}
// we use NSJSONSerialization to parse the JSON formatted response
NSError *jsonError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:loginData options:kNilOptions error:&jsonError];
NSArray *loginArray = responseDictionary[#"loginAccounts"];
// parse the accountId and baseUrl from the response and use in the next request
NSString *accountId = loginArray[0][#"accountId"];
NSString *baseUrl = loginArray[0][#"baseUrl"];
//--- display results
NSLog(#"\naccountId = %#\nbaseUrl = %#\n", accountId, baseUrl);
///////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create Envelope via Template and send the envelope
///////////////////////////////////////////////////////////////////////////////////////
// append "/envelopes" URI to your baseUrl and use as endpoint for signature request call
NSString *envelopesURL = [NSString stringWithFormat:#"%#/envelopes",baseUrl];
NSMutableURLRequest *signatureRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:envelopesURL]];
[signatureRequest setHTTPMethod:#"POST"];
[signatureRequest setURL:[NSURL URLWithString:envelopesURL]];
// construct a JSON formatted signature request body (multi-line for readability)
NSDictionary *signatureRequestData = #{#"accountId": accountId,
#"emailSubject" : #"Embedded Sending API call",
#"emailBlurb" : #"email body goes here",
#"templateId" : templateId,
#"templateRoles" : [NSArray arrayWithObjects: #{#"email":email, #"name": name, #"roleName": roleName, #"clientUserId": #"1001" }, nil ],
#"status" : #"sent"
};
// convert request body into an NSData object
NSData* data = [[self jsonStringFromObject:signatureRequestData] dataUsingEncoding:NSUTF8StringEncoding];
// attach body to the request
[signatureRequest setHTTPBody:data];
// authentication and content-type headers
[signatureRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:#"X-DocuSign-Authentication"];
[signatureRequest setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
// Send the signature request...
[NSURLConnection sendAsynchronousRequest:signatureRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *envelopeResponse, NSData *envelopeData, NSError *envelopeError) {
NSError *jsonError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:envelopeData options:kNilOptions error:&jsonError];
NSLog(#"Signature request sent, envelope info is: \n%#\n", responseDictionary);
// parse envelopeId from resposne as it will be used in next request
NSString *envelopeId = responseDictionary[#"envelopeId"];
///////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Signing View (aka recipient view) of the envelope
///////////////////////////////////////////////////////////////////////////////////////
// append /envelopes/{envelopeId}/views/recipient to baseUrl and use in request
NSString *embeddedURL = [NSString stringWithFormat:#"%#/envelopes/%#/views/recipient", baseUrl, envelopeId];
NSMutableURLRequest *embeddedRequest = [[NSMutableURLRequest alloc] init];
[embeddedRequest setHTTPMethod:#"POST"];
[embeddedRequest setURL:[NSURL URLWithString:embeddedURL]];
// simply set the returnUrl in the request body (user is directed here after signing)
NSDictionary *embeddedRequestData = #{#"returnUrl": #"http://www.docusign.com/devcenter",
#"authenticationMethod" : #"none",
#"email" : email,
#"userName" : name,
#"clientUserId" : #"1001" // must match clientUserId set is step 2
};
// convert request body into an NSData object
NSData* data = [[self jsonStringFromObject:embeddedRequestData] dataUsingEncoding:NSUTF8StringEncoding];
// attach body to the request
[embeddedRequest setHTTPBody:data];
// set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
NSDictionary *authenticationHeader = #{ #"Username": email, #"Password" : password, #"IntegratorKey" : integratorKey };
// jsonStringFromObject() function defined below...
[embeddedRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:#"X-DocuSign-Authentication"];
// also set the Content-Type header (other accepted type is application/xml)
[embeddedRequest setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
//*** make an asynchronous web request
[NSURLConnection sendAsynchronousRequest:embeddedRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *embeddedResponse, NSData *embeddedData, NSError *embeddedError) {
if (embeddedError) { // succesful POST returns status 201
NSLog(#"Error sending request %#. Got Response %# Error is: %#", embeddedRequest, embeddedResponse, embeddedError);
return;
}
// we use NSJSONSerialization to parse the JSON formatted response
NSError *jsonError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:embeddedData options:kNilOptions error:&jsonError];
NSString *embeddedURLToken = responseDictionary[#"url"];
//--- display results
NSLog(#"URL token created - please navigate to the following URL to start the embedded signing workflow:\n\n%#\n\n", embeddedURLToken);
}];
}];
}];
}
- (NSString *)jsonStringFromObject:(id)object {
NSString *string = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:object options:0 error:nil] encoding:NSUTF8StringEncoding];
return string;
}

Template for ios notification by Azure Service Bus Notification Hubs

i am using windows azure Service Bus Notification Hubs for ios
i register my device by following code :
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:
#"Endpoint=sb://......" notificationHubPath:#"...."];
NSMutableSet *set = [NSMutableSet set];
[set addObject:#"general"];
[hub registerNativeWithDeviceToken:deviceToken tags:[set copy] completion:^(NSError* error) {
if (error != nil) {
NSLog(#"Error registering for notifications: %#", error);
[self.delegate homePopUpViewControllerEnterButtonPress:self];
}
}];
and sending Notification from .Net Backend by using following code :
var hubClient = NotificationHubClient.CreateClientFromConnectionString(<connection string>, "<notification hub name>");
IDictionary<string, string> properties = new Dictionary<string, string>();
properties.Add("badge", "1");
properties.Add("alert", "This is Test Text");
properties.Add("sound", "bingbong.aiff");
hubClient.SendTemplateNotification(properties, "general");
i able to receive notification but my problem is : notification does not have any property that i added , no sound , no badge ...
if you can please help me
references : http://msdn.microsoft.com/en-US/library/jj927168.aspx
thanks
You registered for native notifications but then you are sending a template notification.
If you want to send native (this will require additional sends if you want to reach devices on different platforms) you have to use
hub.SendAppleNativeNotification(
"{ \"aps\": { \"alert\": \"This is my alert message for iOS!\"}}", "tag");
Please refer to https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html for the iOS payload format.
Alternatively, you can register for template notifications with:
NSString* template = #"{aps: {alert: \"$(myToastProperty)\"}}";
[hub registerTemplateWithDeviceToken:deviceToken
name:#"myToastRegistration"
jsonBodyTemplate:template
expiryTemplate:nil
tags:nil
completion:^(NSError* error) {
if (error != nil) {
NSLog(#"Error registering for notifications: %#", error);
}
}];
Using a template like:
{
“aps”: {
“alert”: “$(alert)”
}
}
Then you can send notifications using hub.SendTemplateNotification like you are already doing.
For more information regarding the difference between template and native please refer to: http://msdn.microsoft.com/en-us/library/jj927170.aspx

How [FBDialogs canPresentShareDialogWithParams:nil] works?

Does anyone make [FBDialogs canPresentShareDialogWithParams:nil] works properly ?
It's always returning me NO. What should I put in params ?
if ([FBDialogs canPresentShareDialogWithParams:nil]) {
NSURL* url = [NSURL URLWithString:#"http://www.google.fr"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
} else {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbComposer setInitialText:#"Google rocks !"];
[self presentViewController:fbComposer animated:YES completion:nil];
} else {
[[[UIAlertView alloc] initWithTitle:#"Informations" message:#"You have to be registered into the settings of your phone in order to share" delegate:nil cancelButtonTitle:#"Close" otherButtonTitles:nil] show];
}
}
According to the HelloFacebookSample from the SDK (and my own experience!):
FBShareDialogParams *p = [[FBShareDialogParams alloc] init];
p.link = [NSURL URLWithString:#"http://developers.facebook.com/ios"];
BOOL canShareFB = [FBDialogs canPresentShareDialogWithParams:p];
canShareFB will return YES if the Facebook app is installed in the system; returns NO if no Facebook app is found.
The fact is it always returns NO.
I think this the issue.
Make sure to pass a non-nil instance of FBShareDialogParams to the canPresentShareDialogWithParams method. The SDK expects to receive a valid instance of FBShareDialogParmas so the SDK can make sure that the version of the Facebook app on the device can actually open the content that's going to be shared.
For example, if FB adds support for sharing video via Share Dialog in a future version of the Facebook app on iOS, the canPresentShareDialogWithParams would return NO if an older version of the Facebook app is present on the device.
I can understand how the docs: https://developers.facebook.com/ios/share-dialog/ might be confusing here (apologies!). We'll update them to reflect this.
Thanks for the feedback; hope that helps!

Resources