I'm trying to build analytics api and got this kind of error message:
../google-api-cpp-client-master/build/lib/libgoogleapis_http.a(media_uploader.cc.o): In function `googleapis::client::MediaUploader::CreateMultipartPayloadReader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
media_uploader.cc:(.text+0x1a15): undefined reference to `googleapis::client::NewCompositeReaderListAndContainerDeleter(std::vector<googleapis::client::DataReader*, std::allocator<googleapis::client::DataReader*> >*)'
media_uploader.cc:(.text+0x1a27): undefined reference to `googleapis::client::NewManagedCompositeDataReader(std::vector<googleapis::client::DataReader*, std::allocator<googleapis::client::DataReader*> > const&, googleapis::Closure*)'
../google-api-cpp-client-master/build/lib/libgoogleapis_http.a(http_request_batch.cc.o): In function `googleapis::client::HttpRequestBatch::PrepareFinalHttpRequest()':
http_request_batch.cc:(.text+0x27ce): undefined reference to `googleapis::client::NewCompositeReaderListAndContainerDeleter(std::vector<googleapis::client::DataReader*, std::allocator<googleapis::client::DataReader*> >*)'
http_request_batch.cc:(.text+0x27e3): undefined reference to `googleapis::client::NewManagedCompositeDataReader(std::vector<googleapis::client::DataReader*, std::allocator<googleapis::client::DataReader*> > const&, googleapis::Closure*)'
collect2: error: ld returned 1 exit status
Very strange that got
no errors if I write this:
flow_->set_default_scopes( "
https://www.googleapis.com/auth/analytics.readonly" );
but the error appears if the line changed to this:
flow_->set_default_scopes( google_analytics_api::AnalyticsService::SCOPES::ANALYTICS_READONLY );
And I always got the error message above when I'm trying to create the AnalyticsService object:
whatever I'm writing this:
analytics_.reset(new AnalyticsService(config_->NewDefaultTransportOrDie()));
or this:
AnalyticsService* ga = new AnalyticsService(config_->NewDefaultTransportOrDie());
I have set the paths for the -I and -L flags well!
Can somebody help me please?
I'm struggling with this api for a long time...
SOURCE:
#include <iostream>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <fstream>
#include <memory>
#include "googleapis/base/macros.h"
#include "googleapis/client/data/data_reader.h"
#include "googleapis/client/service/media_uploader.h"
#include "googleapis/client/service/client_service.h"
#include "googleapis/client/data/data_reader.h"
#include "googleapis/client/transport/http_authorization.h"
#include "googleapis/client/transport/http_request.h"
#include "googleapis/client/transport/http_transport.h"
#include "googleapis/client/transport/curl_http_transport.h"
#include "googleapis/client/auth/file_credential_store.h"
#include "googleapis/client/auth/oauth2_authorization.h"
#include "googleapis/client/data/serializable_json.h"
#include "googleapis/client/util/status.h"
#include "googleapis/client/util/uri_utils.h"
#include "googleapis/strings/strcat.h"
#include "googleapis/strings/stringpiece.h"
#include "../google-api-cpp-client-master/service_apis/analytics/google/analytics_api/analytics_api.h"
int main(int argc, char* argv[])
{
google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
google::InstallFailureSignalHandler();
const std::string jsonFile("XYZ.json");
OAuth2Credential credential_;
std::unique_ptr<AnalyticsService> analytics_;
std::unique_ptr<OAuth2AuthorizationFlow> flow_;
std::unique_ptr<HttpTransportLayerConfig> config_;
googleapis::util::Status status;
config_.reset(new HttpTransportLayerConfig);
HttpTransportFactory* factory = new CurlHttpTransportFactory(config_.get());
config_->ResetDefaultTransportFactory(factory);
flow_.reset(new OAuth2AuthorizationFlow(config_->NewDefaultTransportOrDie()));
std::string json(std::istreambuf_iterator<char>(std::ifstream(jsonFile).rdbuf()),
std::istreambuf_iterator<char>());
flow_->InitFromJson(json);
flow_->set_default_scopes( "
https://www.googleapis.com/auth/analytics.readonly" );
//flow_->set_default_scopes( google_analytics_api::AnalyticsService::SCOPES::ANALYTICS_READONLY );
//analytics_.reset(new AnalyticsService(config_->NewDefaultTransportOrDie()));
AnalyticsService* ga = new AnalyticsService(config_->NewDefaultTransportOrDie());
if (!status.ok()) printf("status.ok() : ERROR - Could not initialize application.\n");
else
{
printf("status.ok() : OK - Application succesfully initialized\n");
//credential_.set_flow(flow_.get());
}
printf("Done\n");
return 0;
}