Thuzi / facebook-node-sdk

Modeled from the (Facebook Javascript SDK), now with the facebook-node-sdk you can now easily write the same code and share between your server (nodejs) and the client (Facebook Javascript SDK).
Other
737 stars 250 forks source link

What is pingFacebook method for? #85

Closed hems closed 9 years ago

hems commented 9 years ago

I just found out that when using this library there is a funny function call, which sends the appId to a page on facebook.

What is it for ? seems like it is unnecessary for the library to work, specially when the response is completely ignored.

https://github.com/Thuzi/facebook-node-sdk/blob/master/fb.js#L635-L663

        pingFacebook = function (appId) {
            var payload = {
                resource: 'thuzi_nodejssdk',
                appid: appId,
                version: version
            };

            try {
                var requestOptions = {
                    method: 'POST'
                    , uri: 'https://www.facebook.com/impression.php'
                    , form: {
                        plugin: 'featured_resources',
                        payload: encodeURIComponent(JSON.stringify(payload))
                    }
                };
                if(options('proxy')) {
                    requestOptions['proxy'] = options('proxy');
                }

                request(
                    requestOptions
                    , function(error, response, body) {
                        // ignore error/response
                    });
            } catch (e) {
                // Eat the error
            }
        };
jarrodconnolly commented 9 years ago

This other C# FB api does something similar, though it has comments suggesting that this should be optional.

The comments there are of interest:

            // Send analytics to Facebook
            //** This should be optional as it affects the privacy status of any app consumingthis framework

https://github.com/facebook-csharp-sdk/facebook-winclient-sdk/blob/master/Source/Facebook.Client/FacebookSessionClient.cs#L34-L79

    public class FacebookSessionClient
    {
        public string AppId { get; set; }
        public bool LoginInProgress { get; set; }
        public FacebookSession CurrentSession { get; private set; }

        public FacebookSessionClient(string appId)
        {
            if (String.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException("appId");
            }
            this.AppId = appId;

            // Send analytics to Facebook
            //** This should be optional as it affects the privacy status of any app consumingthis framework
            SendAnalytics(appId);
        }

        private static bool AnalyticsSent = false;

        private void SendAnalytics(string FacebookAppId = null)
        {
            try
            {
                if (!AnalyticsSent)
                {
                    AnalyticsSent = true;

#if !(WINDOWS_PHONE)
                    Version assemblyVersion = typeof(FacebookSessionClient).GetTypeInfo().Assembly.GetName().Version;
#else                    
                    string assemblyVersion = Assembly.GetExecutingAssembly().FullName.Split(',')[1].Split('=')[1];
#endif
                    string instrumentationURL = String.Format("https://www.facebook.com/impression.php/?plugin=featured_resources&payload=%7B%22resource%22%3A%22microsoft_csharpsdk%22%2C%22appid%22%3A%22{0}%22%2C%22version%22%3A%22{1}%22%7D",
                            FacebookAppId == null ? String.Empty : FacebookAppId, assemblyVersion);

                    HttpHelper helper = new HttpHelper(instrumentationURL);

                    // setup the read completed event handler to dispose of the stream once the results are back
                    helper.OpenReadCompleted += (o, e) => { if (e.Error == null) using (var stream = e.Result) { }; };
                    helper.OpenReadAsync();
                }
            }
            catch { } //ignore all errors
        }
dirkbonhomme commented 9 years ago

Well the description of this project says:

Modeled from the (Facebook Javascript SDK), now with the facebook-node-sdk you can now easily write the same code and share between your server (nodejs) and the client (Facebook Javascript SDK).

I think he's just trying to be feature complete :)

hems commented 9 years ago

okie dokie.

thanks for the info guys.