1、Token生成

接口 : post        https://fabric.io/oauth/token
请求头:Headers Content-Type : application/json
正文: body {
        "grant_type":"password",
        "scope":"organizations apps issues features account twitter_client_apps beta software answers",
        "username":"mimimimimi@qq.com", //登录名
        "password":"123456789", //登录密码
        "client_id":"2c18f8a77609ee6bbac9e53f3768fedc45fb96be0dbcb41defa706dc57d9c931",
        "client_secret":"092ed1cdde336647b13d44178932cba10911577faf0eda894896188a7d900cc9"    
     }

  

2、返回值

{
"access_token": "ccccccccccccccccccccccc",
"token_type": "bearer",
"expires_in": 86400,
"refresh_token": "refresh_tokenqqqqqqqqqqqqq",
   "scope": "organizations apps issues features account twitter_client_apps beta software answers"
}

  

利用  access_token  可以进行后续接口访问。

3、利用 refresh_token 刷新新的token(讲得到的refresh_token<无过期时间>保存下来,刷新token):

接口 : post        https://fabric.io/oauth/token
请求头:Headers Content-Type : application/json
正文: body {
            "grant_type":"refresh_token",
            "refresh_token":"refresh_tokenqqqqqqqqqqqqq"
         }

返回值

{
"access_token": "ccccccccccccccccccccccc",
"refresh_token": "refresh_tokenqqqqqqqqqqqqq"
}

  

4、请求接口   接口文档出处   https://github.com/strongself/fabricio/blob/develop/docs/api_reference.md

举例两个接口

  (1)、GET -  https://fabric.io/api/v2/apps

get     https://fabric.io/api/v2/apps
Headers Authorization: Bearer {access_token}

  

 返回值

 [
{
"id": "11111111",
"name": "8888888888",
"bundle_identifier": "包名",
"base_identifier": "8888888888",
"collect_analytics": true,
"created_at": "2016-08-01T09:03:47Z",
"analytics_app_has_received_data": true,
"analytics_forward_to_google_analytics": false,
"analytics_include_purchase_events_in_forwarded_events": false,
"platform": "android",
"status": "activated",
"latest_build": null,
"icon_url": "https://s3.amazonaws.com555555555icon.png",
"icon_hash": null,
"kit_versions": null,
"sdk_kits": null,
"map_of_available_products": null,
"firebase_crashlytics": false,
"icon32_url": "https://s3.amazonaws.com/assets.crashlytics.com//icon.png",
"icon64_url": "https://s3.amazonaws.com/assets.crashlytics.com/production//icon.png",
"icon128_url": "https://s3.amazonaws.com/assets.crashlytics.com/production//icon.png",
"accounts_count": 23,
"organization_id": "1111111111111",
"watched": null,
"importance_level": null,
"app_link": null,
"dashboard_url": "https://www.fabric.io/333333333333",
"impacted_devices_count": 0,
"unresolved_issues_count": 0,
"crashes_count": 0
}
]

     ***  将红色的记录下来  organization_id  和  app_id  ***

   (2)获取日活

  

接口  get  https://fabric.io/api/v2/organizations/organization_id/apps/app_id/growth_analytics/daily_active.json?start=1478736000&end=1478736000
头设置 Headers Authorization: Bearer {access_token}

  

  返回值,解析需要的值:

{
"build": "all",
"series": [
[
1478736000, //日期
0 //日活
],
[
1478822400,
0
],
[
1481328000,
0
]
],
"start": 1478736000,
"end": 1481328000,
"app_id": "appid--------",
"deltas": {
"week_over_week": {
"delta_fraction": null,
"last_week_value": null
}
}
}

  

完整代码  PHP

 <?php

 class ScriptUserDaily
{
  //保存第一次获取的 refresh_token ,用于下次刷新token用
private $filePath = '/files/fabricToken.json'; public function fire()
{
$access_token = $this->getRefreshToken();
if(empty($access_token))
$access_token = $this->getToken(); $edata = time();
$sdata = $edata - 24 * 3600 * 5; $header = [
"Authorization: Bearer ".$access_token
];      //数据库获取应用,主要获取 organization_id 和 app_id
$appinfo = FanAppInfo::byFabric()->get();
foreach ($appinfo as $appItem){
$fabricid = $appItem->fabricid;
if(empty($fabricid))
continue;        $organization_id = $appItem->organization_id;
$url = "https://fabric.io/api/v2/organizations/$organization_id/apps/$fabricid/growth_analytics/daily_active.json?start=$sdata&end=$edata"; $this->getDatas($url,$header,1); $url2 = "https://fabric.io/api/v2/organizations/$organization_id/apps/$fabricid/growth_analytics/daily_new.json?start=$sdata&end=$edata"; $this->getDatas($url2,$header,2);
}
} private function getRefreshToken(){
//获取 refresh_token 从文件中读取保存的refresh_token
$path = $this->filePath; $JsonData = file_get_contents($path); $rejson = json_decode($JsonData, true);
$refresh_token = $rejson['refresh_token']; //刷新 token
$url = 'https://fabric.io/oauth/token';
$header = [
"content-type: application/json"
];
$body = [
'grant_type' => 'refresh_token',
'refresh_token' => trim($refresh_token)
]; $data = $this->curl_post($url,$header,json_encode($body));
$rejson = json_decode($data, true); $access_token_new = '';
$refresh_token_new = '';
if(isset($rejson['refresh_token']))
$refresh_token_new = $rejson['refresh_token'];
if(isset($rejson['access_token']))
$access_token_new = $rejson['access_token']; if(!empty($refresh_token_new)){
$txt = [
'access_token' => $access_token_new,
'refresh_token' => $refresh_token_new
]; //重新写入新的 refresh_token
$this->writeRefreshToken($txt);
} return $access_token_new;
} private function getToken(){
$url = 'https://fabric.io/oauth/token';
$header = [
"content-type: application/json"
];
$body = [
'grant_type' => 'password',
'scope' => 'organizations apps issues features account twitter_client_apps beta software answers',
'username' => '14141414@qq.com',
'password' => '123456789',
'client_id' => '2c18f8a77609ee6bbac9e53f3768fedc45fb96be0dbcb41defa706dc57d9c931',
'client_secret' => '092ed1cdde336647b13d44178932cba10911577faf0eda894896188a7d900cc9'
]; $data = $this->curl_post($url,$header,json_encode($body));
$rejson = json_decode($data, true); $access_token_new = '';
$refresh_token_new = '';
if(isset($rejson['refresh_token']))
$refresh_token_new = $rejson['refresh_token'];
if(isset($rejson['access_token']))
$access_token_new = $rejson['access_token']; if(!empty($refresh_token_new)){
$txt = [
'access_token' => $access_token_new,
'refresh_token' => $refresh_token_new
]; //重新写入新的 refresh_token
$this->writeRefreshToken($txt);
} return $access_token_new;
} private function writeRefreshToken($txt){
$path = $this->filePath; $myfile = fopen($path, "w");
$txt = json_encode($txt);
fwrite($myfile,$txt);
fclose($myfile);
} private function getDatas($url,$header,,$type){
$resData = $this->curl_get($url,$header);
$datas = json_decode($resData, true); if(!isset($datas['series']))
return ''; $active = 0;
$news = 0;
foreach ($datas['series'] as $item){
$date = date('Y-m-d',$item[0]); if($type == 1){
$active = intval($item[1]);
}elseif($type == 2){
$news = intval($item[1]);
} //处理数据 }
} private function curl_get($url, $header = [], $time = 5){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  if (!empty($header)) {
   curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
   }
   curl_setopt($ch, CURLOPT_TIMEOUT, $time);
   $result = curl_exec($ch);
   curl_close($ch);
   return $result;
  }   private function curl_post($url, $header = [], $body = [], $time = 5){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
   if (!empty($body)) {
   curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
   }
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   if (!empty($header)) {
   curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
   }
   curl_setopt($ch, CURLOPT_TIMEOUT, $time);
   $result = curl_exec($ch);
   curl_close($ch);
   return $result;
  }
}

***  参考文档    https://github.com/strongself/fabricio/blob/develop/docs/api_reference.md ***

fabric Report API的更多相关文章

  1. Python自动化运维工具-Fabric部署及使用总结

    使用shell命令进行复杂的运维时,代码往往变得复杂难懂,而使用python脚本语言来编写运维程序,就相当于开发普通的应用一样,所以维护和扩展都比较简单,更重要的是python运维工具fabric能自 ...

  2. [Python Fabric] [SSH] Mac OS X 10.9 + Vagrant虚拟环境使用Python Fabric进行SSH远程登录的简单实验

    1. ssh客户端生成key $ Generating public/private rsa key pair. Enter file in which to save the key (/Users ...

  3. Python之Fabric模块

    Fabric是基于Python实现的SSH命令行工具,简化了SSH的应用程序部署及系统管理任务,它提供了系统基础的操作组件,可以实现本地或远程shell命令,包括:命令执行.文件上传.下载及完整执行日 ...

  4. Hyperledger Fabric Chaincode for Operators——实操智能合约

    什么是Chaincode(智能合约)? chaincode是一个程序,它是使用Go语言编写的,最终在Java等其他编程语言中实现了指定的接口.chaincode运行在一个被背书peer进程独立出来的安 ...

  5. Python3 模块 -- Fabric自动化模版

    安装 pip3 install fabric3 创建软连接 find / -type f -name "fab" /usr/local/python3/bin/fab ln -s ...

  6. Hyperledger Fabric链码之三

    在<Hyperledger Fabric链码之一>和<Hyperledger Fabric链码之二>中我们介绍了链码的定义,并通过dev网络测试了测试了自己编写的链码程序. 本 ...

  7. Fabric运维从入门到精通

    1. fabric的安装 在windows下的python3中安装fabric: 在python安装根目录下使用pip install fabric 安装 如图: fabric只支持python2不支 ...

  8. fabric 更详尽的用法

    项目发布和运维的工作相当机械,频率还蛮高,导致时间浪费在敲大量重复的命令上. 修复bug什么的,测试,提交版本库(2分钟),ssh到测试环境pull部署(2分钟),rsync到线上机器A,B,C,D, ...

  9. 系统批量运维管理器Fabric详解

    系统批量运维管理器Fabric详解 Fabrici 是基于python现实的SSH命令行工具,简化了SSH的应用程序部署及系统管理任务,它提供了系统基础的操作组件,可以实现本地或远程shell命令,包 ...

随机推荐

  1. ArcGIS 10.3编译旧版本Addin错误的解决办法

    ArcGIS10.2下VS2010的AddIn,在10.3下在VS2012下重新编译出现missing ESRI ArcGIS Add-in SDK错误,导致无法生成esriAddIn安装文件. 该问 ...

  2. 【嵌入式】安装Linux系统到开发板

    一.开发板基本介绍 Flash --相当于硬盘 RAM -- 内存 Micro USB或232串口 连电脑 USB 接口连摄像头 启动方式 选择开关 :SD卡启动或NAND FLASH 启动 USB转 ...

  3. 【Mood 19】DailyBuild 2月

    2月1号 仿美团loading时小人奔跑动画 HTML5定稿了,为什么原生App世界将被颠覆? -----HTML5一改过去卡顿不兼容的毛病,在硬件升级以及苹果谷歌策略变化的背景下,让自己的优势相对于 ...

  4. Spyder更改默认工作路径已经文件路径

    打开spyder,选择菜单栏中的Tools--->Preferences--->Current working directory   然后选择最下面的单选按钮The following ...

  5. 多设备同时安装apk(安卓)

    前几天在做安卓设备的多个设备同时安装的小脚本.因为目前我这边设备有点多,想顺便做一下安装的测试.而且因为公司的app测试人手上有点不足,就想通过这个办法去在安装的时候更方便省事一点. 本来是想弄个复杂 ...

  6. JSP实现用户登录样例

    业务描述 用户在login.jsp页面输入用户名密码登录: 如果用户名为xingoo,密码为123,则跳转到成功界面login_success.jsp,并显示用户登录的名字: 如果用户名密码错误,则跳 ...

  7. Linux --防火墙(一)

    基本组成 表: filter:用来对数据包进行过滤,根据具体的规则要求决定如何处理一个数据包.表内包含三个链,即INOUT.FORWARD.OUTPUT nat表:主要用来修改数据包的IP地址.端口号 ...

  8. spring 跨域 CORS (Cross Origin Resources Share) 跨域

    Spring提供了三种方式跨域 1.CorsFilter 过滤器 2.<mvc:cors> Bean(全局,推荐使用) 3.@CrossOrigin注解 以上三种方式本质都是用来配置Cor ...

  9. HTTP请求方式中8种请求方法(简单介绍)

    简单介绍 HTTP是超文本传输协议,其定义了客户端与服务器端之间文本传输的规范.HTTP默认使用80端口,这个端口指的是服务端的端口,而客户端使用的端口是动态分配的.当我们没有指定端口访问时,浏览器会 ...

  10. js 实现div跟随鼠标移动

    今天看到了一个自己可以随心所欲的拖到div到页面的任意位置.感觉挺好的,就心血来潮的查询了一下,看看网友做的 代码如下: <script>function doit(){ var obj ...