现在通过 BilibiliAPI 可以直接获得账户信息

This commit is contained in:
czp 2018-02-06 13:08:15 +08:00
parent 677cdbad84
commit 34e7ca5043

View File

@ -4,6 +4,7 @@ import com.hiczp.bilibili.api.interceptor.*;
import com.hiczp.bilibili.api.live.LiveService;
import com.hiczp.bilibili.api.live.socket.LiveClient;
import com.hiczp.bilibili.api.passport.PassportService;
import com.hiczp.bilibili.api.passport.entity.InfoEntity;
import com.hiczp.bilibili.api.passport.entity.LoginResponseEntity;
import com.hiczp.bilibili.api.passport.entity.LogoutResponseEntity;
import com.hiczp.bilibili.api.passport.entity.RefreshTokenResponseEntity;
@ -250,6 +251,27 @@ public class BilibiliAPI implements BilibiliServiceProvider, LiveClientProvider
return logoutResponseEntity;
}
public InfoEntity getAccountInfo() throws IOException, LoginException {
InfoEntity infoEntity = getPassportService()
.getInfo(bilibiliAccount.getAccessToken())
.execute()
.body();
switch (infoEntity.getCode()) {
case ServerErrorCode.Common.OK: {
}
break;
case ServerErrorCode.Passport.NO_LOGIN: {
throw new LoginException("no login");
}
default: {
throw new IOException(infoEntity.getMessage());
}
}
return infoEntity;
}
@Override
public LiveClient getLiveClient(long showRoomId) {
return bilibiliAccount.getUserId() == null ?