我正在尝试访问Google 联系人 API,但我的尝试在获得授权时已失败。在其他(网络)语言中,我习惯了 APIConsole 和公共 API 密钥(授权)。
GoogleCredential credential = new GoogleCredential().setAccessToken("<<PublicAPIKey>>");
System.out.println(credential.refreshToken()); // false
Run Code Online (Sandbox Code Playgroud)
这样我就无法刷新令牌并且不确定是否使用公钥作为访问令牌......相反,我尝试了服务帐户:
private static final String USER_ACCOUNT_EMAIL = "xy@gmail.com";
private static final String SERVICE_ACCOUNT_EMAIL = "xy@developer.gserviceaccount.com";
private static final String SERVICE_ACCOUNT_PKCS12_FILE_PATH = "xy.p12";
public App() {
Set<String> scopes = new HashSet<String>();
scopes.add("https://www.google.com/m8/feeds");
try {
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory(new JacksonFactory())
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(scopes)
.setServiceAccountUser(USER_ACCOUNT_EMAIL)
.setServiceAccountPrivateKeyFromP12File(new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
System.out.println(credential.refreshToken());
//System.out.println(credential.getAccessToken());
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException …
Run Code Online (Sandbox Code Playgroud) java authorization google-api google-api-java-client google-oauth
我想在我的Symfony 3.2应用程序中使用Carbon对象而不是SPL\DateTime对象.我在这里找到了一组DoctrineExtension类.
编辑我的config.yml文件:
doctrine:
dbal:
...
types:
carbondatetime: DoctrineExtensions\Types\CarbonDateTimeType
carbondate: DoctrineExtensions\Types\CarbonDateType
carbontime: DoctrineExtensions\Types\CarbonTimeType
mapping_types:
datetime: carbondatetime
date: carbondate
enum: string
time: carbontime
Run Code Online (Sandbox Code Playgroud)
我成功检查了类型是否加载:
Doctrine\DBAL\Types\Type::getTypesMap()
Run Code Online (Sandbox Code Playgroud)
并且映射也正常工作(返回carbondatetime
):
$this->getDoctrine()->getManager()
->getConnection()->getDatabasePlatform()
->getDoctrineTypeMapping('datetime');
Run Code Online (Sandbox Code Playgroud)
我在Doctrine存储库上执行查询,仍然获取DateTime对象.它有两种情况:
@ORM\Column(type="carbondatetime")
\Doctrine\DBAL\Types\Type::overrideType('datetime', 'DoctrineExtensions\Types\CarbonDateTimeType');
是否有最佳实践来覆盖 Doctrine DBAL类型?优选地,在YAML配置中.
谢谢