在我的网站和sql server登录与facebook之间的连接字符串

时间:2014-04-13 01:20:16

标签: asp.net sql-server facebook-graph-api facebook-oauth

我正在做一个poject webbsaite上传照片,我修复了登录facebook,但我的问题是如何在sql server MSSQL中与那些将访问我的网站并登录facebook帐户的人制作一个sql连接字符串? ?PLZ有谁知道?

1 个答案:

答案 0 :(得分:0)

我想存储facebook用户令牌ID,所以当有人用facebook帐户登录我的网站时,我想在我的sql server中获取并保存用户ID。 这是我在我的网站上使用facebook帐户登录的鳕鱼   

    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));

    // Init the SDK upon load
    window.fbAsyncInit = function () {
        FB.init({
            appId: '1407528266185362', // App ID
            channelUrl: '//' + window.location.hostname + '/http://localhost:44963/', // Path to your Channel File
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });

        // listen for and handle auth.statusChange events
        FB.Event.subscribe('auth.statusChange', function (response) {
            if (response.authResponse) {
                // user has auth'd your app and is logged into Facebook
                var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
                FB.api('/me', function (me) {
                    document.getElementById('auth-displayname').innerHTML = me.name;
                    document.getElementById('Email').innerHTML = me.email;
                    document.getElementById('profileImg').src = uid;
                })
                document.getElementById('auth-loggedout').style.display = 'none';
                document.getElementById('auth-loggedin').style.display = 'block';
            } else {
                // user has not auth'd your app, or is not logged into Facebook
                document.getElementById('auth-loggedout').style.display = 'block';
                document.getElementById('auth-loggedin').style.display = 'none';
            }
        });
        $("#auth-logoutlink").click(function () { FB.logout(function () { window.location.reload(); }); });
    }
</script>
<div id="auth-status">
    <div id="auth-loggedout">
        <div class="fb-login-button" autologoutlink="true" scope="email,user_checkins">Login with Facebook</div>
    </div>
    <div id="auth-loggedin" style="display: none">
        Hej <b><span id="auth-displayname"></span></b><a href="#" id="auth-logoutlink">Logga ut!</a><br />
        <b><span id="Email"></span></b>
        <br />
        <img id="profileImg" />
    </div>
</div>
<form id="form1" runat="server">
    <h1>Galleriet</h1>
    <div class="clear"></div>
    <asp:Panel ID="ResponsePanel" runat="server" Visible="false">
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <asp:ImageButton ID="closeImg" runat="server" ImageUrl="Content/delete1.png" CausesValidation="false" OnClick="closeImg_Click" />
    </asp:Panel>
    <div class="clear"></div>
    <asp:Image ID="FullImage" runat="server" Visible="false" />
    <asp:Panel ID="Panel1" runat="server">
        <asp:Repeater ID="Repeater1" runat="server" ItemType="Galleriet.Model.ThumImgUrl" SelectMethod="Repeater1_GetData" OnItemCommand="Repeater1_ItemCommand">

            <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#Item.FileUrl %>' CssClass='<%# FullImage.ImageUrl.EndsWith(Item.Name) ? "ActiveImg" : null %>'>
                    <asp:Image ID="ImageOne" runat="server" ImageUrl='<%#Item.ImgUrl %>' />
                </asp:HyperLink>
            </ItemTemplate>
        </asp:Repeater>
    </asp:Panel>

    <asp:Panel ID="Panel2" runat="server" GroupingText="ladda upp bild.">
        <div>
            <asp:FileUpload ID="TheFileUpload" runat="server" />
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="<img src=Content/wrong.png /> Fel inträffade! Korrigera felet och försök igen." />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Det måste finna ett filnamn." ControlToValidate="TheFileUpload" Display="None"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="<img src=Content/wrong.png /> Giltiga filändelser är gif, jpg och png." ControlToValidate="TheFileUpload" ValidationExpression="^.*\.(gif|GIF|jpg|JPG|png|PNG)$" Display="None"></asp:RegularExpressionValidator>
        </div>


        <div>
            <asp:Button ID="Button1" runat="server" Text="Ladda upp" OnClick="Button1_Click" />
        </div>
    </asp:Panel>
      <script type="text/javascript">
          function showimagepreview(input) {
              if (input.files && input.files[0]) {
                  var filerdr = new FileReader();
                  filerdr.onload = function (e) {
                      $('#imgprvw').attr('src', e.target.result);
                  }
                  filerdr.readAsDataURL(input.files[0]);
              }
          }

    <a href="http://www.facebook.com/sharer.php?u=http://c-sharp-corner.blogspot.in/2012/06/social-share-buttons-in-aspnet.html" title="share on facebook">Click to share on facebook</a>