![]() |
VOOZH | about |
The CData ADO.NET Provider for YouTube Analytics enables you to rapidly develop service-oriented applications using the Windows Communication Foundation (WCF) framework, providing YouTube Analytics data data to OData consumers. This article guides you through creating an entity data model for connectivity and a WCF Data Service to expose OData services. You can then consume the feed with various OData clients, such as Power Pivot or applications using the CData ADO.NET Provider for OData.
Follow the steps below to create a WCF service application that will provide connectivity to YouTube Analytics data via OData.
Use the Package Manager Console in Visual Studio to install the latest version of Entity Framework. Run the following command to download and install Entity Framework automatically:
Install-Package EntityFramework
<configuration> ... <entityFramework> <providers> ... <provider invariantName="System.Data.CData.YouTubeAnalytics" type="System.Data.CData.YouTubeAnalytics.YouTubeAnalyticsProviderServices, System.Data.CData.YouTubeAnalytics.Entities.EF6" /> </providers> </entityFramework> </configuration>
In the Connection properties dialog, select the CData YouTube Analytics Data Source and enter the necessary credentials.
A typical connection string is below:
ContentOwnerId=MyContentOwnerId;ChannelId=MyChannelId;InitiateOAuth=GETANDREFRESH;
YouTube Analytics uses the OAuth authentication standard. You can use the embedded CData OAuth credentials or you can register an application with Google to obtain your own.
In addition to the OAuth values, to access YouTube Analytics data set ChannelId to the Id of a YouTube channel. You can obtain the channel Id in the advanced account settings for your channel. If not specified, the channel of the currently authenticated user will be used.
If you want to generate content owner reports, specify the ContentOwnerId property. This is the Id of the copyright holder for content in YouTube's rights management system. The content owner is the person or organization that claims videos and sets their monetization policy.
π Required connection properties, specified in the Add Connection dialog. (Salesforce is shown.)Specify the data source class and configure access to the new WCF Data Service. In the example below, the Access Rule for the entities is set to All. This means that any user will be able to read and modify data.
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace YouTubeAnalyticsService{
public class YouTubeAnalyticsDataService : DataService<YouTubeAnalyticsEntities> {
public static void InitializeService(DataServiceConfiguration config) {
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
You can now use the service from any OData client; for example, Excel Power Pivot.
Download a free trial of the YouTube Analytics Data Provider to get started:
Download NowLearn more:
π YouTube Analytics IconEasy-to-use YouTube Analytics client enables .NET-based applications to easily consume YouTube Analytics Traffic, Sources, Demographics, Subscribers, etc.