Eu procurei na Internet inteira tentando encontrar um exemplo simples que pudesse me indicar a direção certa, mas sem sorte, então aqui estão minhas perguntas:
Eu quero entrar no Ubuntu One e sincronizar (ou quase ler) arquivos da minha página da web, tudo feito com PHP. As necessidades para acessar arquivos estão todas descritas nessa página: https://one.ubuntu.com/developer/account_admin/issue_tokens/cloud/
Posso concluir a primeira solicitação com:
$url = 'https://login.ubuntu.com/api/1.0/authentications?ws.op=authenticate&token_name=Ubuntu%20One%20@%20try1';
$data = curlPetition(array('URL'=>$url,'USERPWD'=>'user:pass'));
$ar = fopen('uOne','w');fwrite($ar,$data['responseBody']);fclose($ar);
$tokenA = json_decode($data['responseBody'],1);
Ok, curlPetition faz apenas petições básicas de curl. Observe que você precisa de um usuário válido: passe uma conta no ubuntu. Eu recebo a resposta corretamente em json com "consumer_secret", "token", "consumer_key", "name", "token_secret". Até a entrada aparece listada nos aplicativos concedidos pelo ubuntu.
Instalei a mais nova extensão php OAuth PCL e seu bom funcionamento. mas quando tento:
$api_url = 'https://one.ubuntu.com/api/file_storage/v1/';
$conskey = $tokenA['consumer_key'];
$conssec = $tokenA['consumer_secret'];
$token = $tokenA['token'];
$secret = $tokenA['token_secret'];
$oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->enableSSLChecks();
$oauth->setToken($token,$secret);
$oauth->fetch($api_url.'~/Ubuntu%20One/');
print_r($oauth->getLastResponse());
Sou movido para a página "Transação OpenID em andamento", onde você passa ao fazer um login manual na Web. Definitivamente, estou fazendo algo errado. Tentei obter o segundo passo em https://one.ubuntu.com/developer/account_admin/issue_tokens/cloud/ com $ oauth-> fetch, $ oauth-> getAccessToken e $ oauth-> getRequestToken, mesma resposta em todos os Erro 403: S
Eu estava tentando descobrir como a carga útil funciona, mas os principais exemplos são escritos com python, usando "import ubuntuone.couch.auth as auth" que torna o token quase automático.
Vou amar algumas dicas. obrigado
fonte
Respostas:
Acredito que o problema foi que a etapa 2 do fluxo de trabalho "criar um novo token", definido em https://one.ubuntu.com/developer/account_admin/issue_tokens/cloud/ , estava falhando com um 503 porque o serviço foi em alguns pontos neste fim de semana. Você precisará interceptar essa situação e lidar com ela (um 503 indica que você deve tentar novamente a solicitação posteriormente, conforme HTTP padrão).
Eu testei o PHP abaixo (cuidado: eu não sou um hacker de PHP, portanto pode não ser o código mais idiomático) e funciona bem para mim. Ele passa por três etapas:
Você verá as partes individuais comentadas abaixo. Lembre-se de que isso solicita e recebe um novo token; depois de ter o token (após a etapa 2), salve-o em algum lugar; não solicite uma nova sempre.
fonte
Código de uma classe de primeira etapa para conversar com o ubuntuOne
Alguns exemplos de chamadas (srry para a desordem e código comentado, talvez documentação um dia):
Boa sorte, espero que ajude
fonte
Versão atualizada, alguns recursos adicionados, algum bug detectado
fonte
Uau, Stuart Langridge, você é como uma lenda para mim !!.
Acho que amanhã encontrarei um pouco de tempo livre para invadir seu exemplo e ver o que recebo. Enquanto isso, desenvolvi algumas funções baseadas em Curl para fazer login e saquear a página HTML do UbuntuOne. Vou tentar publicá-lo aqui assim que o estabilizar um pouco.
Sim, vou escrever uma API quase completa baseada em PHP e notarei você, só me dê um tempo, estou meio sobrecarregada agora: S
Vou adorar mostrar meu trabalho, talvez um dia eu supere meus medos e me inscreva para trabalhar na Canonical, é como um sonho para mim. No momento em que escrevi uma pequena resenha para mostrar meu projeto atual, terei prazer em enviar uma cópia, se você se importa. Eu quero lançá-lo como software livre, mas sou um dos que precisa abrigar um projeto da web e ter certeza de que é seguro antes de lançá-lo.
(este não é nenhum tipo de link permanente, desculpe) http://marcos.colorvamp.com/mongo/lain-and-ubuntu-one/
E se você checar a página base ... hmm como foi dito na minha terra. "Na casa do ferreiro, existem facas de madeira" :-)
Obrigado pela resposta :-)
fonte