Stats Account campaign v0 convert to v1


#1

I have a conversion of the adsapi from version 0 to version 1, which I believe from the first link below to the second link below, using TweetSharp

//v0
https://dev.twitter.com/ads/reference/get/stats/accounts/%3Aaccount_id/campaigns/%3Aid

	public virtual IEnumerable<TwitterAdsStats> GetAccountCampaignsStats(GetAccountCampaignsStatsOptions options)
	{
		var account_id = options.AccountId;
		var campaign_ids = options.CampaignIds;
		var start_time = options.StartTime;
		var end_time = options.EndTime;
		var granularity = options.Granularity;
		var metrics = options.Metrics;
		var country = options.Country;
		var platform = options.Platform;
			
		
		return WithHammock<IEnumerable<TwitterAdsStats>>(_adsClient, "stats/accounts/{account_id}/campaigns", "", "?account_id=", account_id, "&campaign_ids=", campaign_ids, "&start_time=", start_time, "&end_time=", end_time, "&granularity=", granularity, "&metrics=", metrics, "&country=", country, "&platform=", platform);
	}

//v1
https://dev.twitter.com/ads/reference/1/get/stats/accounts/%3Aaccount_id

        public virtual IEnumerable<TwitterAdsStats> GetAccountStats(GetAccountStatsOptions options)
	{
		var account_id = options.AccountId;
		var entity = options.Entity;
		var entity_ids = options.EntityIds;
		var start_time = options.StartTime;
		var end_time = options.EndTime;
		var granularity = options.Granularity;
		var metric_groups = options.MetricGroups;
		var placement = options.Placement;
			
		
		return WithHammock<IEnumerable<TwitterAdsStats>>(_adsClient, "stats/accounts/{account_id}", "", "?account_id=", account_id, "&entity=", entity, "&entity_ids=", entity_ids, "&start_time=", start_time, "&end_time=", end_time, "&granularity=", granularity, "&metric_groups=", metric_groups, "&placement=", placement);
	}

So, below are my code. In v0 it will call GetAccountCampaignsStats() while in v1 it will call GetAccountStats() with entity CAMPAIGN. Problem is, I’m not getting anything, the return result is NULL, please let me know what is wrong?

//v0

         GetAccountCampaignsStatsOptions options = new GetAccountCampaignsStatsOptions
          {
             AccountId = "18ce54ahyak",                  
             CampaignIds = new List<string> { "4bnmy" },                  
             StartTime = Convert.ToDateTime("2015-02-26 12:13:08.000").Date,
             Granularity = TwitterAdsStats.StatsGranularity.TOTAL
          };

//v1

      TweetSharpNew.TweetSharp.GetAccountStatsOptions options_v1 = 
      new     TweetSharpNew.TweetSharp.GetAccountStatsOptions
        {
             AccountId = "18ce54ahyak",
             Entity = TweetSharpNew.TweetSharp.TwitterAdsStats.StatsEntity.CAMPAIGN,
             EntityIds = new List<string> { "4bnmy" },
             StartTime = Convert.ToDateTime("2015-02-26 12:13:08.000").Date,
              EndTime = Convert.ToDateTime("2016-03-13 18:11:01.000").Date,
             Granularity = TweetSharpNew.TweetSharp.TwitterAdsStats.StatsGranularity.TOTAL,
             MetricGroups = new List<TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups>
                             {
                                TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups.ENGAGEMENT,
                                TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups.WEB_CONVERSION,
                                TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups.MOBILE_CONVERSION,
                                TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups.MEDIA,
                                 TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups.VIDEO,             TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups.LIFETIME_VALUE_MOBILE_CONVERSION,                      TweetSharpNew.TweetSharp.TwitterAdsStats.StatsMetricGroups.BILLING
                             },
             Placement = TweetSharpNew.TweetSharp.TwitterAdsStats.StatsPlacement.ALL_ON_TWITTER
         };

The call v0 vs v1

         //v0          

         var twitterService = new TwitterServiceWrapper(_consumeKey, _consumerSecret, "foo", "bar");
         twitterService.UserToken = "123123";
         twitterService.UserTokenSecret = "123123a";

         //v1

         var twitterServiceV1 = new TwitterServiceWrapper_v1(_consumeKey, _consumerSecret, "foo", "bar");
         twitterServiceV1.UserToken = "123123";
         twitterServiceV1.UserTokenSecret = 123123a";

         //v0

         var resultV0_1 = twitterService.GetUserProfileFor("haiwanDummy"); //OK
         var resultV0_2 = twitterService.GetAccountCampaignsStats(options); //return result, OK
             
         //v1

         var resultV1_1 = twitterServiceV1.GetUserProfileFor("haiwanDummy"); //OK
         var resultV1_2 = twitterServiceV1.GetAccountStats(options_v1); //result is null, why? what is wrong?

Below are the v1 breakpoint right before TweetSharp call…

“stats/accounts/18ce54ahyak?entity=CAMPAIGN&entity_ids=4bnmy&start_time=2015-02-25T16%3A00%3A00Z&end_time=2016-03-12T16%3A00%3A00Z&granularity=TOTAL&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER”

Below are the v0 breakpoint right before TweetSharp call…

“stats/accounts/18ce54ahyak/campaigns?campaign_ids=4bnmy&start_time=2015-02-25T16%3A00%3A00Z&granularity=TOTAL&include_entities=1&include_rts=1”


#2

Hi @aminmonster703

As you can understand not everyone in this community uses the same Programming Language as you.

I think is easier if you can show us your request and your responses.

Regards.


#3

I change the end time to be within 7 days of start time, it will work fine now in v1 API. BTW, I’m wondering, does twitter suppose to return anything in case of inapproprate input data request? Something like, return json error object mentioning end time is more than 7 days for example? Currently, I’m getting null result on the breakpoint…


#4

Actually, Twitter is returning that kind of errors with that explanation.

Anyway, sometimes the API returns a null response, but it also comes with a 503 error code.


#5

Thanks! I traced back the code and find that it is returning the error, just happen that in that particular breakpoint location, it was null.