Comunidad de diseño web y desarrollo en internet online

Como conectarme a una api cuando piden autentificacion

Citar            
MensajeEscrito el 16 Nov 2009 09:18 am
Estimados amigos son novato en actionscript y flex y ando haciendo unas pruebas de connecion a una api , en este caso de un servidor de un juego , me funciona bien excepto cuando tengo ke autentificar el HTTPService a traves de un apikey userid y charid , hice una cuenta trial para experimentar y poder mostrarles a ver si pueden ayudarme a hacerlo de la forma correcta aca les dejo mi codigo :
Los datos son de la cuenta trial

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
   >
   
<mx:Script>    
<![CDATA[        




private function authAndSend(Service:HTTPService):void        
{               
   var apiKey:String;
   apiKey = 'D1667E9A237B4A87AA42AABFCEC1A89A6BA53DD01B544B1BB48FED167BCE513A';
   var characterID:int;
   characterID = 687488351;

  var userID:int; 
  userID = 5896287;
  

    Service.setRemoteCredentials('{apiKey}', '{characterID}', '{userID}' );                
Service.send();        }        

]]>
</mx:Script>


<mx:HTTPService  id="Service" url="http://api.eve-online.com/eve/char/Standings.xml.aspx    "  resultFormat="text"  />
   <mx:DataGrid width="100%" dataProvider="{Service.lastResult.eveapi.result.standingsTo.rowset.row}" height="330"/>
   <mx:Button id="apiButton"    label="Test API Command"    click="authAndSend(Service)" /><mx:TextArea id="apiResult" />
</mx:Application>


y aca las indicaciones de connecion a la api
http://wiki.eve-id.net/APIv2_Char_Standings_XML


De ante mano muchas gracias y suerte para todos =).

Por bambanx

48 de clabLevel



 

msie8
Citar            
MensajeEscrito el 16 Nov 2009 12:28 pm
Si miras setCredentials recibe estos parámetros:

public function setRemoteCredentials(remoteUsername:String, remotePassword:String, charset:String = null):void

Me parece que no los datos que le estas pasando, luego para que te pase el dato en vez de un literal usa:

Service.setRemoteCredentials(apiKey, characterID, userID);

Finalmente recuerda que esto setea los headers de la llamada (el típico user/pass para acceder a una carpeta) pero hay que ver si tu servicio espera ese tipo de headers para la autentificación o alguna otra cosa.

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 16 Nov 2009 06:40 pm
gracias por la info como decia soy novato , me sugieres alguna otra forma ? ya ke el api me pide otro formato no user pass , si no un api ke es char64 y dos int userid y charid .
Saludos y gracias

Por bambanx

48 de clabLevel



 

msie8
Citar            
MensajeEscrito el 16 Nov 2009 06:42 pm
Tendría que estudiarme el API, en cuanto tenga un rato ;)

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 16 Nov 2009 06:50 pm
jajaj oki , mira si sirve de ayuda en php lo pude hacer asi :
<?
function api($userid, $api, $charid, $dato)
{
$web='http://api.eve-online.com'.$dato;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"$web");
//curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch,CURLOPT_POSTFIELDS,"userID=$userid&apiKey=$api&characterid=$charid");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$api=curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($api);
return $xml;
}

function isk($bytes)
{
$size = $bytes / 1000;
if($size < 1000)
{
$size = number_format($size, 2);
$size .= ' K';
}
else
{
if($size / 1000 < 1000)
{
$size = number_format($size / 1000, 2);
$size .= ' M';
}
else if ($size / 1000 / 1000 < 1000)
{
$size = number_format($size / 1000 / 1000, 2);
$size .= ' B';
}
}
return $size;
}


$userid="5896287";
//$apikey="faKm9Uy9xRtlfYGg3btTriu4B7oAzOESIEDEoMWZZqUy4hA9J8EryIR2kYzFlkzO";
$api="D7E4235279D34BDC8FA7680FB2BBD0A354E7D7E03E144CDABD8F6DBBD2141360";
$charid=687488351;
$dato="/char/AccountBalance.xml.aspx ";
echo "wallet de namen ";
$xml = api($userid, $api, $charid, $dato);
$cosa=$xml->result[0]->rowset->row[balance];
echo isk($cosa);
$dato3='/corp/CorporationSheet.xml.aspx';
$xml2 = api($userid, $api, $charid, $dato3);
$i=1000;
foreach ($xml2->result->rowset[1]->row as $valor) {
$j=$valor[description];
$nombre[$i]=$j;
$i++;
}

?>
el tema seria como hacerlo en actionscript :p y respecto a la api del juego aca me dice los datos ke me pide :
http://wiki.eve-id.net/APIv2_Char_Standings_XML

Por bambanx

48 de clabLevel



 

msie8
Citar            
MensajeEscrito el 16 Nov 2009 06:53 pm
y encontre esto en una web no lo entiendo mucho si alguien me lo pudiera explicar por favor :
service = new HTTPService();
service.contentType = "text/xml";
service.resultFormat = "e4x";
service.useProxy = false;
service.method = "POST";
service.addEventListener(ResultEvent.RESULT, onRestCallResult);
service.addEventListener(FaultEvent.FAULT, onRestCallFault); service.url
= "https://privatesslcerthost.com/"; + path; service.send(params);

gracias.

Por bambanx

48 de clabLevel



 

msie8
Citar            
MensajeEscrito el 16 Nov 2009 06:59 pm
Lo primero es un script en PHP que usa CURL para simular las llamadas, no lo veo de mucha ayuda ya que las llamadas las tienes que hacer desde Flex, lo segundo es una llamada desde HTTPService, solo que en vez de hacerlo usando tags MXML como tu primer POST, lo usa directamente creándolo en ActionScript, si no entiendes que significa cada propiedad de HTTPService revisa la ayuda

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 19 Nov 2009 10:43 am
Ya puede solucionarlo y kedo asi :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="100%"
creationComplete="init()" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#2C2A2A, #000000]">




<mx:Script>
<![CDATA[

import mx.collections.ArrayCollection;
import flash.net.navigateToURL;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;


[Bindable]
private var proxyUrl:String;

private function init():void
{
proxyUrl = Application.application.parameters.proxyUrl;

}


[Bindable]
private var evedatos:ArrayCollection;
private function resultHandler(e:ResultEvent):void
{
evedatos = proxyService.lastResult.eveapi.result.rowset.row as ArrayCollection;

}


private function resultFault(e:FaultEvent):void
{
Alert.show(e.fault.rootCause.toString());
}


]]>
</mx:Script>

<mx:HTTPService
id="proxyService" method="POST"
url="proxy.php"
result="resultHandler(event)" fault="resultFault(event)">
<mx:request>
<url>http://api.eve-online.com/eve/AllianceList.xml.aspx</url>
</mx:request>
</mx:HTTPService>


<mx:VBox width="100%" height="100%">

<mx:Button x="153" y="36" label="Alianzas" width="160"
click="{proxyService.send()}"/>


<mx:Panel x="0" y="0" width="100%" height="100%"
layout="absolute" title="Cross Domain Proxy Demo">


<mx:DataGrid width="100%" height="100%" id="grilla" x="0" dataProvider="{evedatos}"/>





</mx:Panel>
</mx:VBox>
</mx:Application>

SAludos y gracias por la ayuda.

Por bambanx

48 de clabLevel



 

msie8

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.