| Both sides previous revision Previous revision | |
| vendors:cisco:uc:ucce:finesse:gadgetcodesnippets [2024/09/30 17:19] – removed - external edit (Unknown date) 127.0.0.1 | vendors:cisco:uc:ucce:finesse:gadgetcodesnippets [2024/09/30 17:19] (current) – ↷ Page moved from vendors:cisco:uc:finesse:gadgetcodesnippets to vendors:cisco:uc:ucce:finesse:gadgetcodesnippets gerardorourke |
|---|
| | ====== Gadget Code Snippets ====== |
| |
| | ===== MakeRequest ===== |
| | |
| | <html> |
| | <p>The makeRequest() callback parameter is passed a javascript object with the following standard fields:</p> |
| | <ul> |
| | <li>"data" - Parsed data of the response, if applicable. This will contain a different type of data depending on the type of request that was made. See the a:ContentType parameters for information about what to expect in this field. The raw response text is returned if the response could not be parsed.</li> |
| | <li>"errors" - This will contain an array of any errors that occurred when making this request. For example, if a 500 error occurred in the request: "500 error" </li> |
| | <li>"headers" - An object containing the response headers. Header names are used as the keys for this object.</li> |
| | <li>"rc" - This is a numeric value representing the HTTP status code of the response.</li> |
| | <li>"text" - This will return the unparsed text of the response.</li> |
| | </ul> |
| | <p>Additionally, several OAuth-specific fields may be returned:</p> |
| | <ul> |
| | <li>"oauthApprovalUrl" - If this value is specified, the user needs to visit an external page to approve the gadget's request to access data. Use of a pop-up window to direct the user to the external page is recommended. Once the user has approved access, the gadget can repeat the makeRequest call to retrieve the data.</li> |
| | <li>"oauthError" - If this value is specified, it indicates an OAuth-related error occurred. The value will be one of a set of string constants that can be used for programmatically detecting errors. The constants are undefined for opensocial-0.8, but implementers should attempt to agree on a set of useful constant values for standardization in opensocial-0.9.</li> |
| | <li>"oauthErrorText" - If this value is specified, it indicates an OAuth-related error occurred. The value is free-form text that can be used to provide debugging information for gadget developers.</li> |
| | </ul> |
| | </html> |
| | |
| | <code JavaScript> |
| | _clientLogger.log("handleResponse(): The response status code is: " + response.rc); |
| | _clientLogger.log("response.data :" + response.data); |
| | _clientLogger.log("response.headers :" + JSON.stringify(response.headers)); |
| | _clientLogger.log ("responseTextJSON: " + JSON.stringify(response.text)); |
| | </code> |
| | |
| | === Output === |
| | <code JavaScript> |
| | handleResponse(): The response status code is: 200 |
| | response.data :{"authToken":"f3ea48e6-006d-4063-8839-00daf1416476"} |
| | response.headers :{"content-type":["application/json; charset=UTF-8"],"content-length":["52"],"server":["Microsoft-HTTPAPI/2.0"],"date":["Sun, 03 May 2020 07:46:52 GMT"]} |
| | responseTextJSON: "{\"authToken\":\"f3ea48e6-006d-4063-8839-00daf1416476\"}" |
| | </code> |
| | |
| | |
| | === Content Type Example ==== |
| | Access the Header Object Property |
| | Reference: https://www.w3schools.com/js/js_object_properties.asp |
| | <code JavaScript> |
| | console.log("BLAH*****: "+ response.headers["content-type"]); |
| | </code> |