当我按照Hadley的R Google Deogle Oauth2.0演示访问Fusion桌子时,刷新令牌不可用。
演示:https://github.com/hadley/httr/blob/master/demo/oauth2-google.r
修改后的示例"离线"尝试:
google_token <- oauth2.0_token(oauth_endpoints("google"), myapp,
scope = "https://www.googleapis.com/auth/fusiontables",
type= "offline",
use_oob = FALSE,
cache = TRUE)
非常感谢有关如何检索刷新令牌的任何指示。
更新: 使用以下代码,返回带有google_token $凭据的字符串。这是此处引用的授权码:https://developers.google.com/accounts/docs/OAuth2WebServer#offline
google_token <- oauth2.0_token(oauth_endpoints("google"), myapp,
scope = "https://www.googleapis.com/auth/fusiontables",
type= "access_type='offline'",
use_oob = FALSE,
cache = TRUE)
谢谢。
答案 0 :(得分:1)
我在这里参加派对有点晚了,但希望这对某人有所帮助。上周我发现了这个问题,因为我正在努力解决同样的问题。和你一样,我阅读了API文档并在“oauth2.0_token()”函数的“type”字段中尝试了“离线”,但它搞砸了响应。我从github存储库下载了httr包源文件并浏览了一下。经过一番挖掘后,我找到了解决方法。
如果你修改了oauth-init中的“authorize-url”变量:
#pragma version(1)
#pragma rs java_package_name(jp.drmh.wajin.newversion)
#include "common.rsh"
rs_allocation real;
rs_allocation img;
bool is_forward;
uint32_t len;
uint32_t levels;
uint16_t __attribute__((kernel)) root(uint16_t in, uint32_t x, uint32_t y){
// rsDebug("call",x);
float realval[512];
float imagval[512];
if(is_forward){
for (uint32_t i = 0; i < len; i++) {
realval[i]=rsGetElementAt_float(real,x*512+i);
imagval[i]=rsGetElementAt_float(img,x*512+i);
//rsDebug("values", realval[i], imagval[i]);
}
}else{
for (uint32_t i = 0; i < len; i++) {
realval[i]=rsGetElementAt_float(img,x*512+i);
imagval[i]=rsGetElementAt_float(real,x*512+i);
}
}
float costable[256],sintable[256];
for (uint32_t i = 0; i < len / 2; i++) {
costable[i]=cos(2 * M_PI * i / len);
sintable[i]=sin(2 * M_PI * i / len);
}
// Bit-reversed addressing permutation
for (uint32_t i = 0; i < len; i++) {
uint32_t j = bit_reverse32(i);
uint32_t ans=j>>(32 - levels);
if (j > i) {
float temp = realval[i];
realval[i] = realval[j];
realval[j] = temp;
temp = imagval[i];
imagval[i] = imagval[j];
imagval[j] = temp;
}
}
for (uint32_t size = 2; size <= len; size *= 2) {
uint32_t halfsize = size / 2;
uint32_t tablestep = len / size;
for (uint32_t i = 0; i < len; i += size) {
for (uint32_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
float tpre=realval[j + halfsize] * costable[k]
+ imagval[j + halfsize] * sintable[k];
float tpim = -realval[j + halfsize] * sintable[k]
+ imagval[j + halfsize] * costable[k];
realval[j + halfsize] = realval[j] - tpre;
imagval[j + halfsize] = imagval[j] - tpim;
realval[j] += tpre;
imagval[j] += tpim;
}
}
if (size == len)
break;
}
if(!is_forward){
for(uint32_t i = 0; i < len; i++){
realval[i]=realval[i]/len;
imagval[i]=imagval[i]/len;
rsDebug("values", realval[i], imagval[i]);
}
for (uint32_t i = 0; i < len; i++) {
rsSetElementAt_float(real, realval[i], x*512+i);
rsSetElementAt_float(img, imagval[i], x*512+i);
}
}
return in;
}
到此:
authorize_url <- modify_url(endpoint$authorize, query = compact(list(
client_id = app$key,
scope = scope_arg,
redirect_uri = redirect_uri,
response_type = "code",
state = state)))
然后获取oauth-token和所有依赖函数(包括oauth-init),你将得到一个刷新令牌。出于某种原因,当oauth_token调用init_oauth2.0时,它不会传递“type”参数。
这是一个讨厌的解决方法,我可能犯了几个罪,但确实有效。你会得到一个刷新令牌。