Tuesday, 21 March 2017

Posting text in LinkedIn

Posting text in LinkedIn:

Step-1:

Create an ASP.Net solution, add an aspx page, copy the local host URL.

Step-2:

Login to your LinkedIn account. Then open the https://developer.linkedin.com/ link.

Step-3:

Click on MyApp then Create application. Then create new application from will appear. Fill all the field and submit it, the application will be create.































Step-4:

Now check all the Default Application Permission, and give the local host link in Authorization Redirect URLs and click on add. Then click on update.




























Step-5:

From the left side menu bar goto JavaScript and set the Valid SDK Domain (your local host URL) and click on add. Then


















Step-6:

Then write the following script in your aspx page.

<head runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>

    <script type="text/javascript" src="//platform.linkedin.com/in.js">
  api_key: Your API Key(ClientId)
  authorize: true
  onLoad: onLinkedInLoad
</script>
<script type="text/javascript">

    // Setup an event listener to make an API call once auth is complete
    function onLinkedInLoad() {
        IN.Event.on(IN, "auth", shareContent);
    }

    // Handle the successful return from the API call
    function onSuccess(data) {
        console.log(data);
    }

    // Handle an error response from the API call
    function onError(error) {
        console.log(error);
    }
    // Use the API call wrapper to share content on LinkedIn
    function shareContent() {
        debugger;
        var msg = document.getElementById('<%=TextBox1.ClientID%>').value;
        // Build the JSON payload containing the content to be shared
       
        var payload = {
            "comment": msg ,
            "visibility": {
                "code": "anyone"
            }
        };
        IN.API.Raw("/people/~/shares?format=json")
          .method("POST")
          .body(JSON.stringify(payload))
          .result(onSuccess)
          .error(onError);
    }
</script>
</head>

Add control-


<body>
    <form id="form1" runat="server">

    <div>
        <script type="in/Login"></script>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      
        <asp:Button ID="Button1" runat="server" Text="Click Here" OnClientClick="shareContent()" />
    </div>
    </form>
</body>




Posting Image and Text in Facebook

Posting Image and Text in Facebook:

For Posting images and text messages in Facebook, you have to follow these steps:

Step-1:

Create a new ASP.Net Solution and Add a Default.aspx page. Then copy its localhost url.

Step-2:

Log in to your Facebook account. Then Open this given link https://developers.facebook.com/apps.

Step-3:


Click on “Add a new App”. Then a popup window will open.


Step-4:

In this popup, write your Application Name in Display Name and Select Category. Then Click on Create App ID. Then it will ask for security check. Then Submit it.


Step-5:

After Submit a developer Application window will open. And go to the settings page.


Then Copy the App ID and App Secret for your solution.

Step-6:

Then click on Add Platform and choose website. And set your website or localhost url.


Step-7:

Go to your menu bar option, select Add Product and then choose Facebook login option.



Step-8:

Now go to the Facebook Login Page. And give your website url or localhost url in Valid OAuth redirect URIs. Then click on save changes


Step-9:

Then go to the App Review page. Then set your created App public true.


Then click on start a submission button.


Then select all items from this submission page and click add items.


Step-10:

Now you go to your ASP.Net solution. And a “aspsnippets.facebookapi.dll” file in your solution reference.

Step-11:

Go to your Default.aspx page and add controls in your design page.

<asp:FileUpload ID="FileUpload1" runat="server" />
    <br />
    <br />
    <asp:TextBox ID="txtMessage" runat="server" TextMode = "MultiLine"></asp:TextBox>
    <hr />
    <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick = "UploadPhoto" />
 

Step-12:

Write this below coding in your “Default.aspx.cs” page:
1.Add Namespace:
using ASPSnippets.FaceBookAPI;


2. Write this below coding in “Page_Load” event.  

        FaceBookConnect.API_Key = "404417453247103";
        FaceBookConnect.API_Secret = "03c91fd2103207adb84508249e6848dd";
        if (!IsPostBack)
        {
            HttpPostedFile updfile=(HttpPostedFile)Session["File"];
            string code = Request.QueryString["code"];
            if (!string.IsNullOrEmpty(code))
            {
                if (updfile.FileName != "")
                {
                    FaceBookConnect.PostFile(code, "me/photos", updfile, Session["Message"].ToString());
                    Session["File"] = null;
                    Session["Message"] = null;
                }
                else
                {
                    Dictionary<string, string> data = new Dictionary<string, string>();
                    data.Add("message", Session["Message"].ToString());
                    FaceBookConnect.Post(code, "me/feed", data);
                    Session["File"] = null;
                    Session["Message"] = null;
                }
            }
        }
   

3.Write these code in button click event:

        Session["File"] = FileUpload1.PostedFile!=null?FileUpload1.PostedFile:null;
        Session["Message"] = txtMessage.Text;
        FaceBookConnect.Authorize("user_photos,publish_actions", Request.Url.AbsoluteUri.Split('?')[0]);
        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Image has been shared.');", true);