Hi everyone,
i created successfully my FamilySearch-Developer Account. Than, i made a Subclass of Xojo.Net.HTTPSocket called FamilySearchAPI.
[h]FamilySearchAPI[/h]
Constants
- ClientID As Text // My Developer ID
- GrantType As Text = “password”
- Password As Text // My Developer Password
- URL As Text = “https://sandbox.familysearch.org”
- URL_Search As Text = “/platform/tree/search”
- URL_Token As Text = “/cis-web/oauth2/v3/token”
- User As Text // My Developer Username
Properties - AccessToken As Text
- Dict As Xojo.Core.Dictionary
Then i add these class to a Window and add a Button and TextArea. Buttons Action Event:
[code]Using Xojo.Core
Using Xojo.Data
Dim FamilySearch_Access As Text
Dim header As Dictionary
Dim json As Text
Dim data As MemoryBlock
FamilySearch_Access = “?username=” + FamilySearchAPI.User _
+ “&grant_type=” + FamilySearchAPI.GrantType _
+ “&client_id=” + FamilySearchAPI.ClientID _
+ “&password=” + FamilySearchAPI.Password
header = New Dictionary
header.Value(“Accept”) = “application/json”
json = GenerateJSON(header)
data = TextEncoding.UTF8.ConvertTextToData(json)
FamilySearchAPI.SetRequestContent(data, “application/x-www-form-urlencoded”)
FamilySearchAPI.Send(“POST”, FamilySearchAPI.URL + FamilySearchAPI.URL_Token + FamilySearch_Access)[/code]
The PageReceived-Event of the FamilySearchAPI-Object:
[code]Dim jsonData As Text
jsonData = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(Content)
Me.dict.RemoveAll
Me.dict = Xojo.Data.ParseJSON(jsonData)
If Me.dict.HasKey(“access_token”) Then
Me.AccessToken = Me.dict.Value(“access_token”)
End If
TextArea1.Text = jsonData + EndOfLine + EndOfLine + HTTPStatus.ToText[/code]
All Codes above working fine! But now, i wanna use FamilySearch’s Person Search.
Request
GET /platform/tree/search?q=motherGivenName:Clarissa+fatherSurname:Heaton+motherSurname:Hoyt+surname:Heaton+givenName:Israel+fatherGivenName:Jonathan
Accept: application/x-gedcomx-atom+json
Authorization: Bearer YOUR_ACCESS_TOKEN_HERE
I added a second Button and his Action-Event looks like this:
[code]Using Xojo.Core
Using Xojo.Data
Dim FamilySearch_Access As Text
FamilySearch_Access = “?q=motherGivenName:Clarissa+fatherSurname:Heaton+motherSurname:Hoyt+surname:Heaton+givenName:Israel+fatherGivenName:Jonathan”
Dim header As New Dictionary
header.Value(“Accept”) = “application/x-gedcomx-atom+json”
header.Value(“Authorization”) = "Bearer " + FamilySearchAPI.AccessToken
Dim json As Text
json = GenerateJSON(header)
Dim data As MemoryBlock
data = TextEncoding.UTF8.ConvertTextToData(json)
FamilySearchAPI.SetRequestContent(data, “application/x-www-form-urlencoded”)
Dim outputFile As Xojo.IO.FolderItem = Xojo.IO.SpecialFolder.Documents.Child(“data.json”)
FamilySearchAPI.Send(“GET”, FamilySearchAPI.URL + FamilySearchAPI.URL_Search + FamilySearch_Access, outputFile)[/code]
And this returns noting. Only a nil JSON-File Why? It should look like the response on the FamilySearch-API JSON-Sample above.
How to use Xojo.Net.HTTPSocket to get Data?
Thank you all.