月度归档:2021年07月

以Api的方式获取Instagram博主数据

Ins Api调用说明

Ins分2种用户,一种是普通的,一种是专业的,普通用户是无法满足我们需求的。

专业用户需要满足以下准备工内容:
1、一个Ins的商务账户
2、一个Facebook开发者账号
3、Facebook开发者中心建立一个App并审核通过(注意APP的类型要选择为business)
4、增加2个Product,一个facebook登录和instagram graph api
5、在app preview里去选择”pages_show_list”和”instagram_basic” 2个权限,具体别的权限看情况去选择,在正式使用之前需要要去申请这些权限。

开始,参照:https://developers.facebook.com/docs/instagram-api/getting-started

把个人的Ins账户转为专业账户
关联 https://help.instagram.com/399237934150902?fbclid=IwAR1VFQ403f16ZUvApnMtsDYuNRHcwg9il0qh4G5DDluZHNSfJU3wKK4-Zb4

登录FaceBook账户指南
https://developers.facebook.com/docs/facebook-login/web

通过php登录的话,要参考github上的代码:
https://github.com/facebookarchive/php-graph-sdk/tree/master
有一个坑是要开启session,sdk是通过session来判断state参数是否一样的,这样防止非法调用

我们需要用到这个instagram_basic api的权限,需要进行“business verification”,
https://developers.facebook.com/docs/permissions/reference/instagram_basic

验证的帮助说明在这里:
https://developers.facebook.com/docs/development/release/business-verification

 

验证步骤:
https://developers.facebook.com/apps/305829777821658/app-review/submissions/current-request/?business_id=219068326242405

在提交审核的时候,有一个deletion url,是当对方删除数据的时候,我们也要一起删除,见:
https://developers.facebook.com/docs/development/create-an-app/app-dashboard/data-deletion-callback

API的调用参考:https://developers.facebook.com/docs/instagram-api/getting-started

获取用户信息
https://graph.facebook.com/v11.0/me/accounts?access_token=
获取用户在IG里的信息
https://graph.facebook.com/v11.0/103288701887981?fields=instagram_business_account&access_token={access-token}
根据IG ID获取用户在IG里的信息
https://graph.facebook.com/v3.2/17841405339389255?fields=biography,id,username,website,followers_count,follows_count,media_count,profile_picture_url&access_token=
获取用户的IG Media列表
https://graph.facebook.com/v11.0/17841405339389255/media?access_token=
根据IG的ID获取详情
https://graph.facebook.com/v11.0/17912414743825369?fields=id,media_type,like_count,comments_count,media_url,owner,timestamp&access_token=

 

MySQL笔记

MySQL里的日期与时间

格式化:select DATE_FORMAT(now(), ‘%Y-%m-%d %T’);
从1970年1月1日到指定时间的天数:select to_days(now());

取当前时间:
select now(), current_timestamp(),current_timestamp,current_time, curtime(),current_date, curdate(), sysdate();
sysdate()函数是这个函数执行时候的时间,其它的是语句开始执行的时间。

时间的加减:

DATE_ADD(date,INTERVAL expr type)
DATE_SUB(date,INTERVAL expr type)
DATEDIFF(date1,date2),2个时间的天数
TIMESTAMPDIFF(type,date1,date2),2个时间的差额
TIMESTAMPADD(type,int_expr,date1),加时间

 

存储过程

set @var = '';
set @var2 = 'fff';
set @var = @var2;

-- 这种只能用在declare了的变量
set var = 'sdfdf';

-- 这里不会输出返回结果,只会设置变量
select `day` into @var from redash_queue_flush_sem_base_data limit 1;
-- 这里在设置变量的同时,也会返回
select @day:=`day` from redash_queue_flush_sem_base_data limit 1;


CREATE DEFINER=`dealam_stat_prod`@`%` PROCEDURE `flush_sem_base_data`()
-- 注意这里的BYEBYE,在里面用leave BYEBYE就可以退出了,存储过程里没有return之类的功能
BYEBYE:BEGIN
    declare vday varchar(100);
    declare vvar VARCHAR(50);
    declare vvalue VARCHAR(200);
    declare select_done int default 0;
    -- 定义select游标
    declare cur_queue cursor for select `var`, `value` from redash_variable limit 2;
    -- 定义游标是否循环完成的标记变量
    declare continue handler for not found set select_done = 1;
    
    if @queue_count > 0 then
        insert into redash_logs (`what`) values (concat('刷新队列里还有数据:', @queue_count));
        select concat('刷新队列里还有数据:', @queue_count) as msg;
        leave BYEBYE;
    else
        -- 找出待更新订单对应的订单日期,放入待刷新队列中
        insert ignore redash_queue_flush_sem_base_data 
            select distinct(from_unixtime(transaction_time, '%Y-%m-%d')) from da_sem_order where updated_time>@sem_last_update_time order by updated_time;
    end if;
    
    open cur_queue;
    
    loop_label:loop
        -- 注意这里变量前没有加@
        fetch cur_queue into vvar, vvalue;
        -- select_done 前没有加@
        if select_done = 1 then
            leave loop_label;
        end if;
        
        -- 注意这里变量前也没有加@,也就是说如果是declare的变量,好像是不用加的
        select vvar, vvalue;
        set @vvar2 = vvar;
        select @vvar2;
        insert into redash_logs (`what`) values (concat('刷新了sem base data,日期:', vvar));
        
    end loop;
    
END

 

查看未提交的事务
select trx_state, trx_started, trx_mysql_thread_id, trx_query from information_schema.innodb_trx\G;

查看锁信息
select * from information_schema.INNODB_TRX WHERE trx_state=’LOCK WAIT’\G