【发布时间】:2016-05-09 07:27:25
【问题描述】:
我想将 Mpesa API 集成到谷歌表单。 用户使用表单支付,我们说注册费
【问题讨论】:
-
你能把 m 链接到 API.. 好吧,如果它是公开的......
-
从未见过以这种方式编写的 API。请在解决此问题时分享您的发现
我想将 Mpesa API 集成到谷歌表单。 用户使用表单支付,我们说注册费
【问题讨论】:
您现在使用可通过 Safaricom 的developer portal 访问的 M-Pesa RESTful API。 documentation 包含主要编程语言的示例代码 - Python、JavaScript/NodeJS、Java、Ruby。
您现在可以像使用任何其他 RESTful API 一样使用 Google Apps 脚本使用 M-Pesa RESTful API。
【讨论】:
我认为这可以通过使用 Apps 脚本创建一个 google 表单来实现。
表单服务
此服务允许脚本创建、访问和修改 Google 表单。
这是使用 Apps 脚本创建 Google 表单的示例代码。
// Create a new form, then add a checkbox question, a multiple choice question,
// a page break, then a date question and a grid of questions.
var form = FormApp.create('New Form');
var item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?');
item.setChoices([
item.createChoice('Ketchup'),
item.createChoice('Mustard'),
item.createChoice('Relish')
]);
form.addMultipleChoiceItem()
.setTitle('Do you prefer cats or dogs?')
.setChoiceValues(['Cats','Dogs'])
.showOtherOption(true);
form.addPageBreakItem()
.setTitle('Getting to know you');
form.addDateItem()
.setTitle('When were you born?');
form.addGridItem()
.setTitle('Rate your interests')
.setRows(['Cars', 'Computers', 'Celebrities'])
.setColumns(['Boring', 'So-so', 'Interesting']);
Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());
然后您可以在 Apps Scripts 中集成第三方 API。
外部 API
Google Apps 脚本可以与来自整个网络的 API 进行交互。本指南展示了如何在脚本中使用不同类型的 API。
Apps Script 中提供了数十种 Google API,例如 built-in services 或 advanced services。如果您想使用不能作为 Apps 脚本服务提供的 Google(或非 Google)API,您可以通过 URL Fetch service 连接到 API 的公共 HTTP 接口。
以下示例向 YouTube API 发出请求并返回与查询
skateboarding dog匹配的视频供稿。
var url = 'https://gdata.youtube.com/feeds/api/videos?'
+ 'q=skateboarding+dog'
+ '&start-index=21'
+ '&max-results=10'
+ '&v=2';
var response = UrlFetchApp.fetch(url);
Logger.log(response);
同样,以下示例将视频上传到 YouTube。也使用UrlFetchApp.fetch()
var payload = 'XXXXX'; // Replace with raw video data.
var headers = {
'GData-Version': '2',
'Slug': 'dog-skateboarding.mpeg'
// Add any other required parameters for the YouTube API.
};
var url = 'https://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
var options = {
'method': 'post',
'headers': headers,
'payload': payload
};
var response = UrlFetchApp.fetch(url, options);
【讨论】:
请在此处查看我对与您的类似问题的回答:Intergrating Mobile Money like Mpesa and AirtelMoney with Android App
探索使用定制的 Mpesa api 开发 Android 应用程序的可能性,以帮助您在线存储 Mpesa 消息并优化该信息以在 Google 表单上使用
【讨论】: