Mahlzeit
Wie gesagt, ich hatte damals mal damit begonnen, das Projekt aber wieder einschlafen lassen.
Es ist nur ein Anfang, mit dem ich probiert habeb. Dies kann als Ansatz dienen. Die Dokumentation der BOX.API ist eigentlich ziemlich gut,
und so kann man das hier leicht erweitern.
Es fehlt noch eine ganze Menge, aber das kann man alles via XML auslesen verarbeiten ... gerade bei get_account_tree()
Vielleicht können wir das ja gemeinsam erarbeiten
Wichtig, man benötigt einen eigenen API Key. Den muss man sich vorher registrieren lassen.
Wie bereits erwähnt, ist das lediglich ein Test:
Vorgehen: Programm starten, sich im Webgadget anmelden, und wenn alles gut lief, den Button 'Login erfolgreich' drücken -> auf den Debug Output achten!!
Code: Alles auswählen
;BOX.net Include
InitNetwork()
;Dieser muss generiert werden
#BOX_ApiKey = ""
Structure __my_box_net_user_structure__
login.s ;/---
email.s ;| Entsprechend der OpenBox Spezifikation
access_id.s ;|
user_id.s ;|
space_amount.s ;|
space_used.s ;|
max_upload_size.s ;\---
EndStructure
Structure __my_box_net_structure__
MainXMLNode.i
ChildXMLNode.i
BOX_NET_TICKET.s
BOX_NET_ERROR.s ;Kommt aus dem Status
BOX_NET_AUTH_TOKEN.s
BOX_NET_USER.__my_box_net_user_structure__
LogedIn.i
ThreadWatchWebgadget.i
WindowID.i
WebGadgetID.i
ButtonGadgetID.i
WindowEvent.i
EndStructure
Global BOX_NET.__my_box_net_structure__
Procedure.s BOX_GetTicketFromXMLFile(box_xml_file.s)
tmp_return_string.s=""
tmp_box_xml.i=LoadXML(#PB_Any,box_xml_file.s)
If tmp_box_xml.i
main_node.i=MainXMLNode(tmp_box_xml.i)
If main_node.i
If GetXMLNodeName(main_node.i)="response"
tmp_box_childnode.i=ChildXMLNode(main_node.i, 1)
If tmp_box_childnode.i And GetXMLNodeName(tmp_box_childnode.i)="status"
If GetXMLNodeText(tmp_box_childnode.i)="get_ticket_ok"
tmp_box_childnode.i=ChildXMLNode(main_node.i, 2)
If tmp_box_childnode.i And GetXMLNodeName(tmp_box_childnode.i)="ticket"
tmp_return_string.s=GetXMLNodeText(tmp_box_childnode.i)
EndIf
Else
BOX_NET\BOX_NET_ERROR=GetXMLNodeText(tmp_box_childnode.i)
EndIf
EndIf
EndIf
EndIf
FreeXML(tmp_box_xml.i)
EndIf
ProcedureReturn tmp_return_string.s
EndProcedure
Procedure.s BOX_GetAuthTokenFromXMLFile(box_xml_file.s)
tmp_return_string.s=""
tmp_box_xml.i=LoadXML(#PB_Any,box_xml_file.s)
If tmp_box_xml.i
main_node.i=MainXMLNode(tmp_box_xml.i)
If main_node.i
If GetXMLNodeName(main_node.i)="response"
tmp_box_childnode.i=ChildXMLNode(main_node.i, 1)
If tmp_box_childnode.i And GetXMLNodeName(tmp_box_childnode.i)="status"
If GetXMLNodeText(tmp_box_childnode.i)="get_auth_token_ok"
token_childnode.i=ChildXMLNode(main_node.i, 2)
If token_childnode.i And GetXMLNodeName(token_childnode.i)="auth_token"
tmp_return_string.s=GetXMLNodeText(token_childnode.i)
EndIf
Else
BOX_NET\BOX_NET_ERROR=GetXMLNodeText(tmp_box_childnode.i)
EndIf
EndIf
EndIf
EndIf
FreeXML(tmp_box_xml.i)
EndIf
ProcedureReturn tmp_return_string.s
EndProcedure
Procedure.s BOX_get_ticket()
;http://developers.box.net/w/page/12923936/ApiFunction_get_ticket
tmp_return_string.s=""
If ReceiveHTTPFile("https://www.box.net/api/1.0/rest?action=get_ticket&api_key="+#BOX_ApiKey,"test_xml.xml")
Debug "Ticket erhalten"
BOX_NET\BOX_NET_TICKET=BOX_GetTicketFromXMLFile("test_xml.xml")
ProcedureReturn BOX_NET\BOX_NET_TICKET
Else
ProcedureReturn "no_connection"
EndIf
EndProcedure
Procedure BOX_SetAuthToken(tmp_token.s)
BOX_NET\BOX_NET_AUTH_TOKEN=tmp_token.s
EndProcedure
Procedure BOX_get_auth_token()
Debug "holen token"
If ReceiveHTTPFile("https://www.box.net/api/1.0/rest?action=get_auth_token&api_key="+#BOX_ApiKey+"&ticket="+BOX_NET\BOX_NET_TICKET,"test_xml.xml")
BOX_NET\BOX_NET_AUTH_TOKEN=BOX_GetAuthTokenFromXMLFile("test_xml.xml")
Debug "AuthToken -> "+BOX_NET\BOX_NET_AUTH_TOKEN
Debug "AuthToken / Error -> "+BOX_NET\BOX_NET_ERROR
If CreateFile(1,"my_token.txt")
WriteStringN(1, BOX_NET\BOX_NET_AUTH_TOKEN)
CloseFile(1)
EndIf
ProcedureReturn #True
Else
Debug "get auth token -> no_connection"
ProcedureReturn #False
EndIf
EndProcedure
Procedure BOX_GetAccountInfoFromXMLFile(box_xml_file.s)
tmp_return_value.i=#False
tmp_box_xml.i=LoadXML(#PB_Any,box_xml_file.s)
If tmp_box_xml.i
main_node.i=MainXMLNode(tmp_box_xml.i)
If main_node.i
If GetXMLNodeName(main_node.i)="response"
tmp_box_statusnode.i=ChildXMLNode(main_node.i, 1)
If tmp_box_statusnode.i And GetXMLNodeName(tmp_box_statusnode.i)="status"
If GetXMLNodeText(tmp_box_statusnode.i)="get_account_info_ok"
;Status ok -> das nächste ist der User Node
tmp_box_usernode.i=ChildXMLNode(main_node.i, 2)
If tmp_box_usernode.i And GetXMLNodeName(tmp_box_usernode.i)="user"
;Jetzt einfach alle Child Nodes durchgehen und entsprechend verarbeiten
tmp_c_childs.i=XMLChildCount(tmp_box_usernode.i)
If tmp_c_childs.i>0
For c_child.i=1 To tmp_c_childs.i
tmp_child_node.i=ChildXMLNode(tmp_box_usernode.i, c_child.i)
If tmp_child_node.i
;parsen
Select GetXMLNodeName(tmp_child_node.i)
Case "login"
BOX_NET\BOX_NET_USER\login=GetXMLNodeText(tmp_child_node.i)
Case "email"
BOX_NET\BOX_NET_USER\email=GetXMLNodeText(tmp_child_node.i)
Case "access_id"
BOX_NET\BOX_NET_USER\access_id=GetXMLNodeText(tmp_child_node.i)
Case "user_id"
BOX_NET\BOX_NET_USER\user_id=GetXMLNodeText(tmp_child_node.i)
Case "space_amount"
BOX_NET\BOX_NET_USER\space_amount=GetXMLNodeText(tmp_child_node.i)
Case "space_used"
BOX_NET\BOX_NET_USER\space_used=GetXMLNodeText(tmp_child_node.i)
Case "max_upload_size"
BOX_NET\BOX_NET_USER\space_used=GetXMLNodeText(tmp_child_node.i)
EndSelect
EndIf
Next
tmp_return_value.i=#True
Else
;Keine Childs
tmp_return_value.i=#False
EndIf
Else
;Kein User - Node ... na dann raus
tmp_return_value.i=#False
EndIf
Else
;Status nicht in Ordnung
BOX_NET\BOX_NET_ERROR=GetXMLNodeText(tmp_box_statusnode.i)
tmp_return_value.i=#False
EndIf
Else
;kein Status Node -> raus
tmp_return_value.i=#False
EndIf
EndIf
EndIf
FreeXML(tmp_box_xml.i)
EndIf
ProcedureReturn tmp_return_value.i
EndProcedure
Procedure BOX_get_account_info()
Debug "account Infos auslesen"
If ReceiveHTTPFile("https://www.box.net/api/1.0/rest?action=get_account_info&api_key="+#BOX_ApiKey+"&auth_token="+BOX_NET\BOX_NET_AUTH_TOKEN,"test_xml.xml")
If BOX_GetAccountInfoFromXMLFile("test_xml.xml")=#True
Debug "Account war erfolgreich"
Debug BOX_NET\BOX_NET_USER\login
Debug BOX_NET\BOX_NET_USER\email
Debug BOX_NET\BOX_NET_USER\access_id
Debug BOX_NET\BOX_NET_USER\user_id
Debug BOX_NET\BOX_NET_USER\space_amount
Debug BOX_NET\BOX_NET_USER\space_used
Debug BOX_NET\BOX_NET_USER\max_upload_size
ProcedureReturn #True
Else
Debug "Fehler in get_account_info"
ProcedureReturn #False
EndIf
Else
Debug "get_account_info -> no_connection"
ProcedureReturn #False
EndIf
EndProcedure
Procedure BOX_get_account_tree()
Debug "get_account_tree"
If ReceiveHTTPFile("https://www.box.net/api/1.0/rest?action=get_account_tree&api_key="+#BOX_ApiKey+"&auth_token="+BOX_NET\BOX_NET_AUTH_TOKEN+"&folder_id=0¶ms[]=onelevel¶ms[]=nozip","gat_xml.xml")
Debug "account tree erhalten"
; Hier muss die XML Datei ausgelesen werden!!
Else
Debug "get_account_tree -> no_connection"
ProcedureReturn #False
EndIf
EndProcedure
Procedure BOX_logout()
If ReceiveHTTPFile("https://www.box.net/api/1.0/rest?action=logout&api_key="+#BOX_ApiKey+"&auth_token="+BOX_NET\BOX_NET_AUTH_TOKEN,"test_xml.xml")
Debug "logout"
EndIf
EndProcedure
Procedure BOX_OpenLoginWin()
BOX_NET\LogedIn=#False
If BOX_NET\BOX_NET_TICKET="":ProcedureReturn #False:EndIf
BOX_NET\WindowID=OpenWindow(#PB_Any,#PB_Ignore, #PB_Ignore, 600, 400, "Login to BOX.NET",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
BOX_NET\WebGadgetID=WebGadget(#PB_Any,0,0,600,370,"https://www.box.net/api/1.0/auth/"+BOX_NET\BOX_NET_TICKET)
myBrowser.IWebBrowser2 = GetWindowLong_(GadgetID(BOX_NET\WebGadgetID), #GWL_USERDATA)
myBrowser\put_Silent(#True)
BOX_NET\ButtonGadgetID=ButtonGadget(#PB_Any,490,375,100,20,"Login erfolgreich")
quit=0
Repeat
BOX_NET\WindowEvent=WaitWindowEvent()
If BOX_NET\WindowEvent
Select BOX_NET\WindowEvent
Case #PB_Event_CloseWindow
If EventWindow()=BOX_NET\WindowID:quit=1:EndIf
Case #PB_Event_Gadget
If EventGadget()=BOX_NET\ButtonGadgetID
BOX_get_auth_token()
BOX_get_account_info()
BOX_get_account_tree()
BOX_logout()
EndIf
EndSelect
Else
Delay(10)
EndIf
Until quit=1
CloseWindow(BOX_NET\WindowID)
EndProcedure
BOX_get_ticket()
BOX_OpenLoginWin()
Gruß, Morty