emonarafat / socialauth-net

Automatically exported from code.google.com/p/socialauth-net
0 stars 0 forks source link

ExecuteFeed() #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
To the BrickRed Team,
My question is regarding the following line on CustomFeedDemo.aspx

WebResponse wr = 
SocialAuthUser.GetCurrentUser().ExecuteFeed("https://graph.facebook.com/me/album
s", TRANSPORT_METHOD.GET, PROVIDER_TYPE.FACEBOOK);

How can this line of code be changed so that a status post is created on the 
user's facebook wall?

I'm guessing that TRANSPORT_METHOD has to be changed from .GET to .POST, but 
I'm unsure of how to alter the rest of the parameters to accomplish a simple 
post.

Can you please instruct us on how we would alter this line of code to produce a 
simple "Hello World" post on facebook.  

-Thank You
-Gerald Thomas

Original issue reported on code.google.com by gerald.l...@gmail.com on 3 May 2012 at 4:35

GoogleCodeExporter commented 9 years ago
Been trying a variety of things and still haven't figured out how to do this.  
Here is my latest attempt.

byte[] reqbytes = new ASCIIEncoding().GetBytes("Hello World");
                Dictionary<string, string> headers = new Dictionary<string, string>();
                headers.Add("contentType", "application/x-www-form-urlencoded");
                WebResponse wr = SocialAuthUser.GetCurrentUser().ExecuteFeed("https://graph.facebook.com/me/feed?access_token=" + SocialAuthUser.GetCurrentUser().GetAccessToken() + "&fields=message", TRANSPORT_METHOD.POST, PROVIDER_TYPE.FACEBOOK, reqbytes, headers);

Please advise how to create a "Hello World" post to facebook

-Thanks
-Gerald

Original comment by gerald.l...@gmail.com on 3 May 2012 at 7:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi Gerald,

We are taking a look at this issue and will get back to you on Monday.

Warm regards,
SocialAuth team

Original comment by tsg.bric...@gmail.com on 4 May 2012 at 2:47

GoogleCodeExporter commented 9 years ago
I've been able to get this to sometimes work:

protected void Button1_Click(object sender, EventArgs e)
        {
            if (SocialAuthUser.IsConnectedWith(PROVIDER_TYPE.FACEBOOK))
            {
                string body = String.Empty;
                byte[] reqbytes = new ASCIIEncoding().GetBytes(body);
                Dictionary<string, string> headers = new Dictionary<string, string>();
                headers.Add("contentType", "application/x-www-form-urlencoded");
                string RetUrl = "";
                SocialAuthUser.GetCurrentUser().Login(PROVIDER_TYPE.FACEBOOK, RetUrl);
                string AccessTok = SocialAuthUser.GetCurrentUser().GetAccessToken();

                WebResponse wr = SocialAuthUser.GetCurrentUser().ExecuteFeed("https://graph.facebook.com/8615947/feed?access_token=" + AccessTok + "&message=HelloWorld&method=Post", TRANSPORT_METHOD.POST, PROVIDER_TYPE.FACEBOOK, reqbytes, headers);
                StreamReader reader = new StreamReader(wr.GetResponseStream());
            }
            else
            {

            }
        }

After a SocialAuthUser.IsLoggedIn() returns true, I can access this method by 
clicking my button control labeled "Button1".  This calls the method that I've 
just pasted above.  Occasionally this will work and will post to my Facebook 
wall.  But more recently (over the last 12 hours) I cannot get this code to 
execute, because I get an error on the .ExecuteFeed line as follows:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information about 
the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to 
an instance of an object.

Source Error: 

Line 98:                 string AccessTok = 
SocialAuthUser.GetCurrentUser().GetAccessToken();
Line 99:                 
Line 100:                WebResponse wr = 
SocialAuthUser.GetCurrentUser().ExecuteFeed("https://graph.facebook.com/8615947/
feed?access_token=" + AccessTok + "&message=HelloWorld&method=Post", 
TRANSPORT_METHOD.POST, PROVIDER_TYPE.FACEBOOK, reqbytes, headers);
Line 101:                StreamReader reader = new 
StreamReader(wr.GetResponseStream());
Line 102:            }

Source File: c:\Users\glthomas\Documents\Visual Studio 
2010\WebSites\TixPixSVN\Site.master.cs    Line: 100 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   Brickred.SocialAuth.NET.Core.ErrorMessages.CustomFeedExecutionError(String feedUrl, QueryParameters collection) +163
   Brickred.SocialAuth.NET.Core.OAuth2_0server.ExecuteFeed(String feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod, Byte[] content, Dictionary`2 headers) +1328
   Brickred.SocialAuth.NET.Core.Provider.ExecuteFeed(String feedURL, TRANSPORT_METHOD transportMethod, Byte[] content, Dictionary`2 headers) +137
   Brickred.SocialAuth.NET.Core.BusinessObjects.SocialAuthUser.ExecuteFeed(String feedUrl, TRANSPORT_METHOD transportMethod, PROVIDER_TYPE providerType, Byte[] content, Dictionary`2 headers) +309
   Brickred.SocialAuth.NET.Demo.SiteMaster.Button1_Click(Object sender, EventArgs e) in c:\Users\glthomas\Documents\Visual Studio 2010\WebSites\TixPixSVN\Site.master.cs:100

It's almost as though their is a bug in the ExecuteFeed method for handling 
posts.  Not sure if it's an access token problem or not.

Is there a more real-time way that we can work through this problem.  I can set 
up a skype chat with one of your team members and we can put our minds together 
and try to work through this.

-Gerald

Original comment by gerald.l...@gmail.com on 4 May 2012 at 3:27

GoogleCodeExporter commented 9 years ago
Please refer following link.

http://code.google.com/p/socialauth-net/wiki/FAQs?ts=1336201223&updated=FAQs#Pos
ting_a_message_on_Facebook

regards,
Deepak

Original comment by daggar...@brickred.com on 5 May 2012 at 7:03

GoogleCodeExporter commented 9 years ago
This is useful information, however I still think that there is a problem that 
needs to be addressed. The code that I pasted from earlier that was giving me 
the error of (System.NullReferenceException) is no longer giving the error, but 
rather is working without problem.  This is truly perplexing because I 
literally didn't alter any of my source code since I last worked on this 
yesterday.  I've thought about this extensively and have some ideas on what 
might be causing the .ExcuteFeed() method to sometimes return a 
System.NullReferenceException

Here is one hypothesis on what is happening.  If you are sending a lot of posts 
to a facebook wall then facebook can issue an exception because too many posts 
are coming through and therefore issues an action limit to prevent what it 
perceives as spam-like activity.  While this might be a good feature to prevent 
a user's wall from getting spammed it might be the source of this headache of 
the unexplained System.NullReferenceException and makes it difficult to perform 
exhaustive testing since it seems pretty easy to hit the action limit.  I 
wasn't counting how many times I created a test post but I would guess it was 
over 20 but less than 50 posts, before I hit the action limit.  After a certain 
amount of time facebook removes this action limit and then the app is again 
able to make posts.

Facebook has a Graph API Explorer tool which can be found here:
http://developers.facebook.com/tools/explorer/

Now if you use facebook's API graph explorer and cut and paste the access token 
that is generated from SocialAuthUser.GetCurrentUser().GetAccessToken() into 
the graph explorer tool and change the dropdown selection box setting from GET 
to POST and then add "message" as the field and then <some text> in the value 
input and click submit you can actually trick their graph explorer tool to post 
on behalf of your app as though it occurred from a socialauth application.  
Here was the exception message that I was receiving earlier today, when 
perfoming this trick.

{"error":
{"type":"OAuthException","message":"(#341 ) 
Feed action request limit reached"}}

Now, after some time has transpired, if I return to the graph explorer tool and 
paste a socialauth access token into the graph explorer as described above, it 
creates the post and returns the id of the newly created post object into the 
output window of the graph explorer tool.

So here is my theory. And I remind you, it's just a theory because all of your 
socialauth class methods are compiled into binary .dll's and therefore I cannot 
truly peer into the black box of the socialauth class methods.  I wonder if 
inside the method for ExecuteFeed is it looking for the object_id and because 
it cannot find an object_id it instead returns the NullReferenceException.

My other theory is that something entirely different is happening and I am 
being tricked into thinking that this is somehow related to the action limit 
error raising an OAuthException.

I will keep the SocialAuth team informed as I conduct further tests and gather 
more data on this truly peculiar problem

-Thank you for your patience and willingness to work through this with me.
-Gerald

Original comment by gerald.l...@gmail.com on 5 May 2012 at 10:07

GoogleCodeExporter commented 9 years ago
Just to add a few more things that strengthen my theory.  Basically, I think 
that anytime ANY error code is raised whether it's because of facebook's 
servers or poorly formed requests, it's going to cause a 
System.NullReferenceException to be raised during runtime.  I think the 
ExecuteMethod() needs a way of handling the potential for error codes being 
raised by facebook servers as well as any of the other social providers like 
twitter.

I found this list of error codes although I'm not sure how current this list is:
http://fbdevwiki.com/wiki/Error_codes

Any thoughts from the socialauth team?

-Gerald

Original comment by gerald.l...@gmail.com on 5 May 2012 at 10:34

GoogleCodeExporter commented 9 years ago
Hi gerald,

Thanks for trying to find the source of this error. We do think that your 
theory is probably correct and will try to debug the source code

You are incorrect about one thing though - the source code is not a black box. 
You can take the latest source code from the SVN repository and build it 
yourself to confirm the theory.

Warm regards,
SocialAuth team

Original comment by tsg.bric...@gmail.com on 5 May 2012 at 10:38

GoogleCodeExporter commented 9 years ago
# Non-members may check out a read-only working copy anonymously over HTTP.
svn checkout http://socialauth-net.googlecode.com/svn/trunk/ 
socialauth-net-read-only

Original comment by tsg.bric...@gmail.com on 5 May 2012 at 10:40