A general client object (wxFlickrAPI.wxFlickrClient) does all the HTTP communication and hence is needed for any method call (make sure to call the wxFlickrAPI.Photos constructor and other constuctors by providing a valid wxFlickrAPI.wxFlickrClient pointer).
A ready-to-use client (including an event handler handling socket events) can be created using a factory (wxFlickrClientFactory).
The client will post events (of type wxFlickrEvent) if something interesting happens.
m_pClient = NULL;
A factory will create the client for you.
wxFlickrClientFactory Fact;
Any flickr client needs an API-key and a shared secret (see http://www.flickr.com/services/api/auth.spec.html)
Fact.SetAPIKey(::wxGetTextFromUser("enter a valid API key", "API key needed")); Fact.SetSharedSecret(::wxGetTextFromUser("enter the corresponding shared secret", "secret needed"));
Now a type of communication may be chosen (REST, XML-RPC or SOAP, see http://www.flickr.com/services/api/)...
Fact.SetType(REST);
...and the client can be created.
m_pClient = Fact.CreateClient();
Since the client will post wxFlickrEvent objects whenever something interesting happens, you will need to set an event handler (here we assume that your current context is an event handler).
m_pClient->SetFlickrHandler(this);
Now you are ready to create some API object and call some method.
Photos *pPhotos = new Photos(m_pClient); wxString sArg = ::wxGetTextFromUser("enter an argument (e.g. tags)"); pPhotos->SetArg(sArg, ::wxGetTextFromUser("enter a value for "+ sArg +" argument")); pPhotos->Search();
Make sure to set all arguments for the method call by calling wxFlickrAPI.wxFlickrAPIMethod.SetArg. Also make sure to delete the API objects but only do so if they are not needed anymore (during method execution they are stored in the client object and used for handling flickr responses).
BEGIN_EVENT_TABLE(wxFlickrFrame, wxFrame) EVT_FLICKR(wxFlickrFrame::OnFlickrEvent) END_EVENT_TABLE()
void wxFlickrFrame::OnFlickrEvent(wxFlickrEvent& event) { if (event.GetType() == wxFlickrEvent::GotFrob) { // let's open a browser window here... AuthData *pAuthData = (AuthData*)event.GetData(); if (!::wxLaunchDefaultBrowser(pAuthData->GetLoginLink())) wxLogError("Failed to start default browser with login link:\n%s", pAuthData->GetLoginLink()); delete pAuthData; } else if (event.GetType() == wxFlickrEvent::Error) { wxFlickrError *pError = (wxFlickrError*)event.GetData(); wxString sErr = wxString::Format("There was an error. It says:\n%s",pError->GetErrorMessage()); if (pError->GetFlickrErrorCode() > -1) sErr += wxString::Format("\n\nIt's a flickr.com error and its error code is %i.", pError->GetFlickrErrorCode()); ::wxMessageBox(sErr, "Error!", wxICON_ERROR); delete pError;
... etc. You might want to check out wxFlickrEvent and wxFlickrEvent.Type.