SlideShare a Scribd company logo
1 of 22
Using the Google SOAP APIs with 
Salesforce 
Ami Assayag, 
Architect, CRM Science 
PhillyForce DUG Leader 
@AmiAssayag 
Yad Jayanth, 
Advanced Developer, CRM Science 
Dallas DUG Co-Organizer 
@YadJayanth
Safe Harbor 
Safe harbor statement under the Private Securities Litigation Reform Act of 1995: 
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of 
the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking 
statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service 
availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future 
operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of 
our services. 
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, 
new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or 
delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and 
acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and 
manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization 
and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our 
annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and 
others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. 
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be 
delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. 
Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Ami Assayag 
Architect, CRM Science 
PhillyForce DUG Leader
Yad Jayanth 
Advanced Developer, CRM Science 
Dallas DUG Co-Organizer
Digital Advertising Project 
• Doubleclick For Publishers (DFP) 
• Advertising management platform 
• SOAP API (xml) 
• Oauth 2.0 (json)
Project Setup 
DFP 
• Client already has account 
• Get Network Code 
• Enable API access 
Google Developer Console 
• Create a project (Google’s “Connected App”) 
• Get Client Id and Client Secret
Create Project in the Console
Create New 
Client ID
Record 
Client ID and 
Client Secret
Google Oauth 2.0 Authentication
Authorization 
OAuth 2.0 Handshake 
• The Web Server Applications Flow : 
– The goal is to get the access token needed to 
access the API 
– We will store the access token in a custom setting 
to be readily available for use in future callouts 
– Use the refresh token to get future access 
tokens to make the callouts
Authorization 
Code Sample 
• Leverage custom settings to persist authorization related information: 
– From API specs 
• Endpoint 
• Scope 
– From Google Console 
• Client secret 
• Client ID 
– From DFP 
• Network Code 
– From Oauth handshake 
• Access token 
• Refresh token
Initiate OAuth Flow to Get Auth Code 
public string getAuthCodeUrl(string redirectUri) { 
// use the URL used when authenticating a google user 
pagereference pr = new pagereference(custSetting.AuthEndpoint__c + 'auth'); 
// add the necessary parameters 
pr.getParameters().put('response_type', 'code'); 
pr.getParameters().put('client_id', custSetting.ClientId__c); 
pr.getParameters().put('redirect_uri', redirectUri); 
pr.getParameters().put('scope', custSetting.Scope__c); 
// add required parameters needed to get an be able to use a refresh token 
pr.getParameters().put('access_type', 'offline'); 
pr.getParameters().put('approval_prompt', 'force'); 
return pr.getUrl(); 
}
Get Access Token – Prep Work 
Create internal class in the image of the json response. 
public class AccessTokenResponse { 
string access_token { get; set; } 
string refresh_token { get; set; } 
string token_type { get; set; } 
integer expires_in { get; set; } 
string id_token { get; set; } 
public AccessTokenResponse() {} 
}
Access Token Callout 
Once the user authenticated, the returned URL will include an auth code that can 
be exchanged for an access token. 
public void getAccessToken(string authCode) { 
// prepare a string to send to google as body 
string body = 'code= authCode; 
body += '&client_id= custSetting.ClientId__c; 
body += '&client_secret= custSetting.ClientSecret__c; 
body += '&redirect_uri= custSetting.redirectUri__c; 
body += '&grant_type=authorization_code'; 
// HTTP callout to Google to exchange the auth code with an access token 
// use internal class from last slide to deserialize json response 
Authenticate(body); 
}
Google SOAP API Callouts
Apex Tools for a Google SOAP API 
• Force.com Google Data API Toolkit 
– Older APIs - authentication methods are deprecated 
• Download WSDL 
– Difficult to overcome all conversion issues 
• Use HTTP callouts 
– Make http callouts with SOAP body (XML)
Simplified Look at SOAP XML Body 
<envelope> 
<Header> 
<RequestHeader type="SoapRequestHeader"> 
<authentication type="OAuth"> 
<parameters>Bearer My_Access_Token</parameters> 
</authentication> 
<networkCode type="string"> 
My_Network_Code 
</networkCode> 
<applicationName type="string"> 
My_Google_Project_Name 
</applicationName> 
</RequestHeader> 
</Header> 
<Body> 
My_SOAP_Body 
</Body> 
</envelope>
Properly Formatted SOAP XML Body 
<?xml version="1.0" encoding="UTF-8"?> 
<env:envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<env:Header> 
<RequestHeader actor="http://schemas.xmlsoap.org/soap/actor/next" 
mustUnderstand="0" xsi:type="ns1:SoapRequestHeader" 
xmlns:ns1="https://www.google.com/apis/ads/publisher/v201403" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<ns1:authentication xsi:type="ns1:OAuth" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<ns1:parameters>Bearer My_Access_Token</ns1:parameters> 
</ns1:authentication> 
<ns1:networkCode xsi:type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
My_Network_Code 
</ns1:networkCode> 
<ns1:applicationName xsi:type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
My_Google_Project_Name 
</ns1:applicationName> 
</ns1:RequestHeader> 
</env:Header> 
<env:Body> 
My_SOAP_Body 
</env:Body> 
</env:envelope>
Sample Callout 
public void SimpleCalloutToGoogle(string endpoint, string method, string body){ 
// set up the request 
HttpRequest req = new HttpRequest(); 
req.setEndpoint(endpoint); 
req.setMethod(method); 
req.setTimeout(10000); 
// set the headers and body 
req.setHeader('Content-Type', 'text/xml; charset=UTF-8'); 
req.setHeader('SOAPAction', ''); 
// make the callout 
Http h = new Http(); 
HttpResponse res = h.send(req); 
// inspect results with XmsStreamReader... 
}
Using the Google SOAP APIs with 
Salesforce 
Ami Assayag, 
Architect, CRM Science 
PhillyForce DUG Leader 
@AmiAssayag 
Yad Jayanth, 
Advanced Developer, CRM Science 
Dallas DUG Co-Organizer 
@YadJayanth

More Related Content

What's hot

Level Five Capabilities 2015
Level Five Capabilities 2015Level Five Capabilities 2015
Level Five Capabilities 2015
Jeffrey Swartz
 

What's hot (18)

Ready, Set, Deploy: How Place Technology Streamlined Deployment on the AppExc...
Ready, Set, Deploy: How Place Technology Streamlined Deployment on the AppExc...Ready, Set, Deploy: How Place Technology Streamlined Deployment on the AppExc...
Ready, Set, Deploy: How Place Technology Streamlined Deployment on the AppExc...
 
Journey to the AppExchange: How to Launch Into a New Ecosystem
Journey to the AppExchange: How to Launch Into a New EcosystemJourney to the AppExchange: How to Launch Into a New Ecosystem
Journey to the AppExchange: How to Launch Into a New Ecosystem
 
Getting to Yes: How to build executive alignment to win big on the AppExchange
Getting to Yes: How to build executive alignment to win big on the AppExchangeGetting to Yes: How to build executive alignment to win big on the AppExchange
Getting to Yes: How to build executive alignment to win big on the AppExchange
 
Webinar: Acting like a top 25 Salesforce ISV - Product Marketing Strategies
Webinar: Acting like a top 25 Salesforce ISV - Product Marketing StrategiesWebinar: Acting like a top 25 Salesforce ISV - Product Marketing Strategies
Webinar: Acting like a top 25 Salesforce ISV - Product Marketing Strategies
 
[Webinar] Acting Like a Top 25 ISV: How Tech Support Drives ACV Growth
[Webinar] Acting Like a Top 25 ISV: How Tech Support Drives ACV Growth[Webinar] Acting Like a Top 25 ISV: How Tech Support Drives ACV Growth
[Webinar] Acting Like a Top 25 ISV: How Tech Support Drives ACV Growth
 
Strategic Partnerships: The New Key to Innovation
Strategic Partnerships: The New Key to InnovationStrategic Partnerships: The New Key to Innovation
Strategic Partnerships: The New Key to Innovation
 
Webinar: Acting Like a Top 25 ISV - Demo Org Optimization
Webinar: Acting Like a Top 25 ISV - Demo Org OptimizationWebinar: Acting Like a Top 25 ISV - Demo Org Optimization
Webinar: Acting Like a Top 25 ISV - Demo Org Optimization
 
CodeScience webinar - Product Management and GTM for Work.com's Command Center
CodeScience webinar - Product Management and GTM for Work.com's Command CenterCodeScience webinar - Product Management and GTM for Work.com's Command Center
CodeScience webinar - Product Management and GTM for Work.com's Command Center
 
Customer Success 2.0 - in the 20's vs. in the 10's
Customer Success 2.0 - in the 20's vs. in the 10'sCustomer Success 2.0 - in the 20's vs. in the 10's
Customer Success 2.0 - in the 20's vs. in the 10's
 
CodeScience webinar: AppExchange Partners Benchmarks & Predictions for 2020
CodeScience webinar: AppExchange Partners Benchmarks & Predictions for 2020CodeScience webinar: AppExchange Partners Benchmarks & Predictions for 2020
CodeScience webinar: AppExchange Partners Benchmarks & Predictions for 2020
 
Improve Customer Experience with a Self-Service Customer Portal
Improve Customer Experience with a Self-Service Customer PortalImprove Customer Experience with a Self-Service Customer Portal
Improve Customer Experience with a Self-Service Customer Portal
 
Cloud Journey- Partner Advantage
Cloud Journey- Partner AdvantageCloud Journey- Partner Advantage
Cloud Journey- Partner Advantage
 
Level Five Capabilities 2015
Level Five Capabilities 2015Level Five Capabilities 2015
Level Five Capabilities 2015
 
Lightning Web Components - A new era, René Winkelmeyer
Lightning Web Components - A new era, René WinkelmeyerLightning Web Components - A new era, René Winkelmeyer
Lightning Web Components - A new era, René Winkelmeyer
 
Pal software ppt
Pal software pptPal software ppt
Pal software ppt
 
How to Develop a VR/AR/MR Experience with Independent Talent
How to Develop a VR/AR/MR Experience with Independent TalentHow to Develop a VR/AR/MR Experience with Independent Talent
How to Develop a VR/AR/MR Experience with Independent Talent
 
APIs are not a technical challenge
APIs are not a technical challengeAPIs are not a technical challenge
APIs are not a technical challenge
 
IdeaExchange Reimagined - Shaping Salesforce Products, Scott Allan, Jennifer ...
IdeaExchange Reimagined - Shaping Salesforce Products, Scott Allan, Jennifer ...IdeaExchange Reimagined - Shaping Salesforce Products, Scott Allan, Jennifer ...
IdeaExchange Reimagined - Shaping Salesforce Products, Scott Allan, Jennifer ...
 

Similar to CRM Science - Dreamforce '14: Using the Google SOAP API

Business Mashups Best of the Web APIs
Business Mashups Best of the Web APIsBusiness Mashups Best of the Web APIs
Business Mashups Best of the Web APIs
dreamforce2006
 
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Ami Assayag
 

Similar to CRM Science - Dreamforce '14: Using the Google SOAP API (20)

Using the Google SOAP API
Using the Google SOAP APIUsing the Google SOAP API
Using the Google SOAP API
 
Business Mashups Best of the Web APIs
Business Mashups Best of the Web APIsBusiness Mashups Best of the Web APIs
Business Mashups Best of the Web APIs
 
OpenID Connect and Single Sign-On for Beginners
OpenID Connect and Single Sign-On for BeginnersOpenID Connect and Single Sign-On for Beginners
OpenID Connect and Single Sign-On for Beginners
 
Tour of Heroku + Salesforce Integration Methods
Tour of Heroku + Salesforce Integration MethodsTour of Heroku + Salesforce Integration Methods
Tour of Heroku + Salesforce Integration Methods
 
Cutting Edge Mobile Development in the App Cloud
Cutting Edge Mobile Development in the App CloudCutting Edge Mobile Development in the App Cloud
Cutting Edge Mobile Development in the App Cloud
 
Navi Mumbai Salesforce DUG meetup on integration
Navi Mumbai Salesforce DUG meetup on integrationNavi Mumbai Salesforce DUG meetup on integration
Navi Mumbai Salesforce DUG meetup on integration
 
Integrate Salesforce with Google Glass Using the Mirror API
Integrate Salesforce with Google Glass Using the Mirror APIIntegrate Salesforce with Google Glass Using the Mirror API
Integrate Salesforce with Google Glass Using the Mirror API
 
[MBF2] Plate-forme Salesforce par Peter Chittum
[MBF2] Plate-forme Salesforce par Peter Chittum[MBF2] Plate-forme Salesforce par Peter Chittum
[MBF2] Plate-forme Salesforce par Peter Chittum
 
Salesforce platform session 2
 Salesforce platform session 2 Salesforce platform session 2
Salesforce platform session 2
 
Turbo-charge Your Skuid Page with Apex
Turbo-charge Your Skuid Page with ApexTurbo-charge Your Skuid Page with Apex
Turbo-charge Your Skuid Page with Apex
 
Building Dynamic UI with Visual Workflow Runtime API
Building Dynamic UI with Visual Workflow Runtime APIBuilding Dynamic UI with Visual Workflow Runtime API
Building Dynamic UI with Visual Workflow Runtime API
 
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
 
Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex
 
Data.com APIs in Action ? Bringing Data to Life in Salesforce
Data.com APIs in Action ? Bringing Data to Life in SalesforceData.com APIs in Action ? Bringing Data to Life in Salesforce
Data.com APIs in Action ? Bringing Data to Life in Salesforce
 
The Power of Salesforce APIs World Tour Edition
The Power of Salesforce APIs World Tour EditionThe Power of Salesforce APIs World Tour Edition
The Power of Salesforce APIs World Tour Edition
 
Visualforce Hack for Junction Objects
Visualforce Hack for Junction ObjectsVisualforce Hack for Junction Objects
Visualforce Hack for Junction Objects
 
Introduction to Data.com APIs
Introduction to Data.com APIsIntroduction to Data.com APIs
Introduction to Data.com APIs
 
Streaming API with Java
Streaming API with JavaStreaming API with Java
Streaming API with Java
 
Introduction to Developing Android Apps With the Salesforce Mobile SDK
Introduction to Developing Android Apps With the Salesforce Mobile SDKIntroduction to Developing Android Apps With the Salesforce Mobile SDK
Introduction to Developing Android Apps With the Salesforce Mobile SDK
 
Hca advanced developer workshop
Hca advanced developer workshopHca advanced developer workshop
Hca advanced developer workshop
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

CRM Science - Dreamforce '14: Using the Google SOAP API

  • 1. Using the Google SOAP APIs with Salesforce Ami Assayag, Architect, CRM Science PhillyForce DUG Leader @AmiAssayag Yad Jayanth, Advanced Developer, CRM Science Dallas DUG Co-Organizer @YadJayanth
  • 2. Safe Harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 3. Ami Assayag Architect, CRM Science PhillyForce DUG Leader
  • 4. Yad Jayanth Advanced Developer, CRM Science Dallas DUG Co-Organizer
  • 5. Digital Advertising Project • Doubleclick For Publishers (DFP) • Advertising management platform • SOAP API (xml) • Oauth 2.0 (json)
  • 6. Project Setup DFP • Client already has account • Get Network Code • Enable API access Google Developer Console • Create a project (Google’s “Connected App”) • Get Client Id and Client Secret
  • 7. Create Project in the Console
  • 9. Record Client ID and Client Secret
  • 10. Google Oauth 2.0 Authentication
  • 11. Authorization OAuth 2.0 Handshake • The Web Server Applications Flow : – The goal is to get the access token needed to access the API – We will store the access token in a custom setting to be readily available for use in future callouts – Use the refresh token to get future access tokens to make the callouts
  • 12. Authorization Code Sample • Leverage custom settings to persist authorization related information: – From API specs • Endpoint • Scope – From Google Console • Client secret • Client ID – From DFP • Network Code – From Oauth handshake • Access token • Refresh token
  • 13. Initiate OAuth Flow to Get Auth Code public string getAuthCodeUrl(string redirectUri) { // use the URL used when authenticating a google user pagereference pr = new pagereference(custSetting.AuthEndpoint__c + 'auth'); // add the necessary parameters pr.getParameters().put('response_type', 'code'); pr.getParameters().put('client_id', custSetting.ClientId__c); pr.getParameters().put('redirect_uri', redirectUri); pr.getParameters().put('scope', custSetting.Scope__c); // add required parameters needed to get an be able to use a refresh token pr.getParameters().put('access_type', 'offline'); pr.getParameters().put('approval_prompt', 'force'); return pr.getUrl(); }
  • 14. Get Access Token – Prep Work Create internal class in the image of the json response. public class AccessTokenResponse { string access_token { get; set; } string refresh_token { get; set; } string token_type { get; set; } integer expires_in { get; set; } string id_token { get; set; } public AccessTokenResponse() {} }
  • 15. Access Token Callout Once the user authenticated, the returned URL will include an auth code that can be exchanged for an access token. public void getAccessToken(string authCode) { // prepare a string to send to google as body string body = 'code= authCode; body += '&client_id= custSetting.ClientId__c; body += '&client_secret= custSetting.ClientSecret__c; body += '&redirect_uri= custSetting.redirectUri__c; body += '&grant_type=authorization_code'; // HTTP callout to Google to exchange the auth code with an access token // use internal class from last slide to deserialize json response Authenticate(body); }
  • 16. Google SOAP API Callouts
  • 17. Apex Tools for a Google SOAP API • Force.com Google Data API Toolkit – Older APIs - authentication methods are deprecated • Download WSDL – Difficult to overcome all conversion issues • Use HTTP callouts – Make http callouts with SOAP body (XML)
  • 18. Simplified Look at SOAP XML Body <envelope> <Header> <RequestHeader type="SoapRequestHeader"> <authentication type="OAuth"> <parameters>Bearer My_Access_Token</parameters> </authentication> <networkCode type="string"> My_Network_Code </networkCode> <applicationName type="string"> My_Google_Project_Name </applicationName> </RequestHeader> </Header> <Body> My_SOAP_Body </Body> </envelope>
  • 19. Properly Formatted SOAP XML Body <?xml version="1.0" encoding="UTF-8"?> <env:envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <env:Header> <RequestHeader actor="http://schemas.xmlsoap.org/soap/actor/next" mustUnderstand="0" xsi:type="ns1:SoapRequestHeader" xmlns:ns1="https://www.google.com/apis/ads/publisher/v201403" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns1:authentication xsi:type="ns1:OAuth" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ns1:parameters>Bearer My_Access_Token</ns1:parameters> </ns1:authentication> <ns1:networkCode xsi:type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> My_Network_Code </ns1:networkCode> <ns1:applicationName xsi:type="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> My_Google_Project_Name </ns1:applicationName> </ns1:RequestHeader> </env:Header> <env:Body> My_SOAP_Body </env:Body> </env:envelope>
  • 20. Sample Callout public void SimpleCalloutToGoogle(string endpoint, string method, string body){ // set up the request HttpRequest req = new HttpRequest(); req.setEndpoint(endpoint); req.setMethod(method); req.setTimeout(10000); // set the headers and body req.setHeader('Content-Type', 'text/xml; charset=UTF-8'); req.setHeader('SOAPAction', ''); // make the callout Http h = new Http(); HttpResponse res = h.send(req); // inspect results with XmsStreamReader... }
  • 21.
  • 22. Using the Google SOAP APIs with Salesforce Ami Assayag, Architect, CRM Science PhillyForce DUG Leader @AmiAssayag Yad Jayanth, Advanced Developer, CRM Science Dallas DUG Co-Organizer @YadJayanth