我需要在方框连接中设置代理。但不能得到任何参考代码到use.Can有人给我解决方案吗?
发布于 2015-10-19 15:08:58
BoxAPIConnection接口=新代码(BoxAPIConnection);
Proxy proxy = null;
try {
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName("proxy URL"), PortNo));
} catch (UnknownHostException e) {
e.printStackTrace();
}
api.setProxy(proxy);
发布于 2019-05-27 00:53:17
我在没有代理的BoxDeveloperEditionAPIConnection上也遇到了同样的问题。我创建了下面的代码来克服这个问题,它提供了在到期时间后自动刷新的令牌:
import com.box.sdk.BoxConfig;
import com.box.sdk.BoxDeveloperEditionAPIConnection;
import com.box.sdk.DeveloperEditionEntityType;
import com.box.sdk.IAccessTokenCache;
import com.eclipsesource.json.JsonObject;
import java.net.Proxy;
public class MyBoxAPIConnection extends BoxDeveloperEditionAPIConnection {
private IAccessTokenCache accessTokenCache;
private String entityID;
private DeveloperEditionEntityType entityType;
public MyBoxAPIConnection(BoxConfig boxConfig, IAccessTokenCache accessTokenCache, Proxy proxy) {
this(boxConfig.getEnterpriseId(), DeveloperEditionEntityType.ENTERPRISE, boxConfig, accessTokenCache);
this.setProxy(proxy);
this.tryRestoreUsingAccessTokenCache();
}
public MyBoxAPIConnection(String entityId, DeveloperEditionEntityType entityType, BoxConfig boxConfig,
IAccessTokenCache accessTokenCache) {
super(entityId, entityType, boxConfig, accessTokenCache);
}
private void tryRestoreUsingAccessTokenCache() {
if (this.accessTokenCache == null) {
// no cache specified so force authentication
this.authenticate();
} else {
String cachedTokenInfo = this.accessTokenCache.get(this.getAccessTokenCacheKey());
if (cachedTokenInfo == null) {
// not found; probably first time for this client config so authenticate; info will then be cached
this.authenticate();
} else {
// pull access token cache info; authentication will occur as needed (if token is expired)
JsonObject json = JsonObject.readFrom(cachedTokenInfo);
this.setAccessToken(json.get("accessToken").asString());
this.setLastRefresh(json.get("lastRefresh").asLong());
this.setExpires(json.get("expires").asLong());
}
}
}
private String getAccessTokenCacheKey() {
return String.format("/%s/%s/%s/%s", this.getUserAgent(), this.getClientID(), this.entityType.toString(),
this.entityID);
}
}
https://stackoverflow.com/questions/32779453
复制相似问题