Browse Month: August 2014

Enterprise App Experience at Raleigh, NC (USA)

Woohoo!! It was my first onsite experience ever. I visited THE United States Of America. It was a majestic experience. When got this news from Nishant & Ankita, I was really very excited that ‘I will FLY’ in my life first time. And also was having mixed feeling that how I’ll manage traveling, whether I’ll be able to talk in English the way Americans do, bla bla.

I went for a complex iOS project, client was truly helpful during my stay in States. Client was very much talented and a professional person. I left quite impressed with his application ideas and grasping power of technical terms. Made a lot of American friends and also got opportunity to see an American wedding closely.

Work experience was really awesome and also learned plenty of things. Because of this onsite I got opportunity to roam around marvelous city New York ūüôā

This trip built confidence in me to travel alone. I am grateful that I got opportunity to go to USA. All credit goes to Nanostuffs!!

… Minakshi Bhosale, Senior iOS Developer/Consultant @ Nanostuffs.

IMG_1143

IMG_1147

Paypal REST API – How does Tokens work.

At the very first User Login:

 

  1. 1. Obtain an Authorization Code

{

“response_type”: “authorization_code”,

“response”: {

“code”: “EBYhRW3ncivudQn8UopLp4A28xIlqPDpAoqd7biDLpeGCPvORHjP1Fh4CbFPgKMGCHejdDwe9w1uDWnjPCp1lkaFBjVmjvjpFtnr6z1YeBbmfZYqa9faQT_71dmgZhMIFVkbi4yO7hk0LBHXt_wtdsw”,

},

“client”: {

“environment”: “live”,

“paypal_sdk_version”: “2.0.0”,

“platform”: “iOS”,

“product_name”: “PayPal iOS SDK”

}

}

 

  1. Get Refresh Token & a temporary Access Token:

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Access tokens can be used for all our transactions but they last for very short time, just 9 seconds mostly.

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Refresh tokens have a lifetime of 10 years.

–¬†¬†¬†¬†¬†¬†¬†¬†¬† So what we going to do is, we‚Äôll store Refresh Token for each user in our database along with her/her all other details.

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Once you get above Auth Code, call this:

curl 'https://api.paypal.com/v1/oauth2/token' 
    -H "Content-Type: application/x-www-form-urlencoded" 
    -H "Authorization: Basic QWZV...==" 
    -d 'grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code= EBYhRW3ncivudQn8UopLp4A28xIlqPDpAoqd7biDLpeGCPvORHjP1Fh4CbFPgKMGCHejdDwe9w1uDWnjPCp1lkaFBjVmjvjpFtnr6z1YeBbmfZYqa9faQT_71dmgZhMIFVkbi4yO7hk0LBHXt_wtdsw'

 

–¬†¬†¬†¬†¬†¬†¬†¬†¬† You‚Äôll get this response:

{
    "access_token": "6oyryV79E.KtpAvPudpI8VIko.ntdPikU9HCDfg0tO0",
    "expires_in": 900,
    "refresh_token": "MFYQJTPW3zlCAjznPs2D0VQlQXwiEfTesR-dRiU_qhbUngzxR3NmeBxqKELcmGtSI739R-awwvOyGVO1LJbowy7n8Ul3vsf5HQDTCzUlDylqBvW0",
    "scope": "https://api.paypal.com/v1/payments/.* https://uri.paypal.com/services/payments/futurepayments",
    "token_type": "Bearer"
}

 

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Use above access token & call this to get customer details:

curl -v https://api.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid 
    -H "Content-Type:application/json" 
    -H "Authorization: Bearer 6oyryV79E.KtpAvPudpI8VIko.ntdPikU9HCDfg0tO0"

 

–¬†¬†¬†¬†¬†¬†¬†¬†¬† You‚Äôll get this response:

{
   "address":{
      "postal_code":"95131",
      "locality":"San Jose",
      "region":"CA",
      "country":"US",
      "street_address":"3 Main St"
   },
   "family_name":"Smith",
   "language":"en_US",
   "phone_number":"4082560980",
   "locale":"en_US",
   "name":"Roger Smith",
   "email":"rsmith@somewhere.com",
   "account_type":"PERSONAL",
   "birthday":"1982-08-02",
   "given_name":"Roger",
   "user_id":"https://www.paypal.com/webapps/auth/identity/user/jG8zVpn2toXCPmzNffW1WTRLA2KOhPXYybeTM9p3ct0"
}

 

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Store everything above along with most important Refresh Token (MFYQJTPW3zlCAjznPs2D0VQlQXwiEfTesR-dRiU_qhbUngzxR3NmeBxqKELcmGtSI739R-awwvOyGVO1LJbowy7n8Ul3vsf5HQDTCzUlDylqBvW0) to your database.

 

 

 

At subsequent same User Logins:

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Get Refresh Token for that User from our Amazon RDS.

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Call this to get Access Token:

curl 'https://api.paypal.com/v1/oauth2/token' 
    -H "Content-Type: application/x-www-form-urlencoded" 
    -H "Authorization: Basic QWZVa...==" 
    -d 'grant_type=refresh_token&refresh_token= MFYQJTPW3zlCAjznPs2D0VQlQXwiEfTesR-dRiU_qhbUngzxR3NmeBxqKELcmGtSI739R-awwvOyGVO1LJbowy7n8Ul3vsf5HQDTCzUlDylqBvW0'

 

–¬†¬†¬†¬†¬†¬†¬†¬†¬† You‚Äôll get this response:

{
    "access_token": "WfXdnxmyJtdF4q59ofxuQuAAk6eEV-Njm6puht3Nk3w",
    "app_id": "APP-3TS46380HB829954H",
    "expires_in": 900,
    "scope": "https://api.paypal.com/v1/payments/.* https://uri.paypal.com/services/payments/futurepayments",
    "token_type": "Bearer"
}

 

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Use above access token for all further API calls.

–¬†¬†¬†¬†¬†¬†¬†¬†¬† Note: Above token expires in 9 seconds, for before every API call you‚Äôll have call above to get new access token.

 

How to add Chatter Feed for a record in visualforce pages

Chatter feeds show you recent activities performed by people and on records in your Salesforceorganization. Salesforce Touch lets you view your Chatter feed, group feeds, profile feeds, and record feeds.

You must follow people and records to see their updates in your Chatter feeds. Chatter feeds display on profiles, groups, the Home tab, topic detail pages, and on record detail pages. Typically, you see feed updates for:

  • Chatter feed comments and posts
  • Posts, comments, and files on Chatter groups you’re a member of
  • Shared files and links
  • Tasks and events
  • Converted leads
  • Record field changes, like changes to record owner and closed opportunities and cases

<!— code for Chatter Feed for Login User —>

<apex:page >

<apex:outputPanel layout=”block” style=”overflow:auto; height:540px; width:500px; margin:0 1px”>

<chatter:feed entityId=”{!$User.Id}”/>

</apex:outputPanel>

</apex:page>

Hope this helps you.

Thank You!

 

Adding Event to Native calendar in iOS

Add Eventkit framework to your project

//Code Snippet:

EKEventStore *store;

store=[[EKEventStore alloc] init];

//for iOS 7.0 and above we need to have the permission of user for using eventkit that is the calendar

//ask for permission:

[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)

{

// handle access here

if(granted)

{

//configure event:

EKEvent *addNewEvent=[EKEvent eventWithEventStore:store];

addNewEvent.startDate=fromDate;

addNewEvent.endDate=toDate;

EKCalendar *defaultCalendar=[store defaultCalendarForNewEvents];

addNewEvent.calendar=defaultCalendar;

EKRecurrenceRule *recRule=[[EKRecurrenceRule alloc] init];

addNewEvent.recurrenceRules=[NSArray arrayWithObject:recRule];

 

BOOL status= [store saveEvent:addNewEvent span:EKSpanThisEvent commit:YES error:&error];

if(status)

{

NSLog(@”Successfully saved”);

}

else

{

//error in saving

//¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† NSLog(@”error in saving: %@”,error);

}

}

}

];

 

 

Speech to text conversion in iOS

There are lots of Speech to text conversion techniques are available but each one have their pros and cons. The Google Speech API is more convenient. I tried lot of ways for the conversion, but Google  API is more efficient and quite easy but having insufficient documentation.

I found that the API accepts flac encoded audio file, but in iOS the flac format is not supported. Finally I found the way is to use audio file encoded with linearPCM and with bit rate of 16000.

The configuration for audio is:

Channels       : 1

Sample Rate    : 16000

Precision      : 16-bit

Sample Encoding: 16-bit Signed Integer PCM

 

The settings dictionary for audio recorder is:

NSDictionary *recordSettings = [NSDictionary

dictionaryWithObjectsAndKeys:

[NSNumber numberWithInt:AVAudioQualityMax],     AVEncoderAudioQualityKey,

[NSNumber numberWithInt:16],                    AVEncoderBitRateKey,

[NSNumber numberWithInt: 1],                    AVNumberOfChannelsKey,

[NSNumber numberWithFloat:16000],               AVSampleRateKey,

[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,

nil];

 

And pass the recorded file in NSData format to api as: the most important thing in this is the content type that one use. It should match the audio file configuration

NSString *urlString = [NSString stringWithFormat:@”https://www.google.com/speech-api/v2/recognize?xjerr=1&client=chromium&lang=en-US&key=%@”,GOOGLE_API_KEY]; //GOOGLE_API_KEY: is obtained from google API Access

NSURL *url = [NSURL URLWithString:urlString];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setHTTPMethod:@”POST”];

[request setHTTPBody:byteData];

[request addValue:@”audio/l16; rate=16000″ forHTTPHeaderField:@”Content-Type”];

[request setURL:url];

[request setTimeoutInterval:15];

NSURLResponse *response;

NSError *error = nil;

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; //the data with trancribed result