chobo2
chobo2

Reputation: 85805

Updated version of Facebook client for dotNetOpenAuth

I upgraded to the newest version of DotNetOpenAuth and I was using the "DotNetOpenAuth.ApplicationBlock" which has facebook in it.

However it does not compile anymore so I am wondering where can I get an update version?

//-----------------------------------------------------------------------
// <copyright file="FacebookClient.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.ApplicationBlock {
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using DotNetOpenAuth.Messaging;
    using DotNetOpenAuth.OAuth2;

    public class FacebookClient : WebServerClient {
        private static readonly AuthorizationServerDescription FacebookDescription = new AuthorizationServerDescription {
            TokenEndpoint = new Uri("https://graph.facebook.com/oauth/access_token"),
            AuthorizationEndpoint = new Uri("https://graph.facebook.com/oauth/authorize"),
        };

        /// <summary>
        /// Initializes a new instance of the <see cref="FacebookClient"/> class.
        /// </summary>
        public FacebookClient() : base(FacebookDescription) {
            this.AuthorizationTracker = new TokenManager();
        }
    }
}


//-----------------------------------------------------------------------
// <copyright file="FacebookGraph.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.ApplicationBlock.Facebook {
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Json;
    using System.Text;

    [DataContract]
    public class FacebookGraph {
        private static DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(FacebookGraph));

        [DataMember(Name = "id")]
        public long Id { get; set; }

        [DataMember(Name = "name")]
        public string Name { get; set; }

        [DataMember(Name = "first_name")]
        public string FirstName { get; set; }

        [DataMember(Name = "last_name")]
        public string LastName { get; set; }

        [DataMember(Name = "link")]
        public Uri Link { get; set; }

        [DataMember(Name = "birthday")]
        public string Birthday { get; set; }

        [DataMember(Name = "email")]
        public string Email { get; set; }

        public static FacebookGraph Deserialize(string json) {
            if (String.IsNullOrEmpty(json)) {
                throw new ArgumentNullException("json");
            }

            return Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }

        public static FacebookGraph Deserialize(Stream jsonStream) {
            if (jsonStream == null) {
                throw new ArgumentNullException("jsonStream");
            }
            return (FacebookGraph)jsonSerializer.ReadObject(jsonStream);
        }
    }
}


Error   3   The type or namespace name 'OAuth2' does not exist in the namespace 'DotNetOpenAuth' (are you missing an assembly reference?)   
Error   6   The type or namespace name 'WebServerClient' could not be found (are you missing a using directive or an assembly reference?)
Error   7   The type or namespace name 'AuthorizationServerDescription' could not be found (are you missing a using directive or an assembly reference?)    
Error   2   The type or namespace name 'Json' does not exist in the namespace 'System.Runtime.Serialization' (are you missing an assembly reference?)   
Error   4   The type or namespace name 'DataContractAttribute' could not be found (are you missing a using directive or an assembly reference?) 
Error   5   The type or namespace name 'DataContract' could not be found (are you missing a using directive or an assembly reference?)  
Error   8   The type or namespace name 'DataContractJsonSerializer' could not be found (are you missing a using directive or an assembly reference?)    

Upvotes: 2

Views: 2249

Answers (1)

Andrew Arnott
Andrew Arnott

Reputation: 81801

If by "newest", you mean CTP3 (4.0.0.11165), you should firstly know that that is known to not work with Facebook because Facebook implements an older version of OAuth 2.0.

As far as the build break, it looks like either you're compiling against a DotNetOpenAuth.dll that does not include OAuth 2.0 support. or for some reason the build failed to resolve the reference. Look for warnings above the errors in the build log.

Upvotes: 2

Related Questions