On a remote client, I'm trying to create a new list in a sharepoint site. Right now, I'm building a CAML string and sending it via http post to my sharepoint site. I've used this method to update list items and create dws folders, but I can't seem to get AddList to work. I get an error "Remove server returned error:NotFound."
here is my CAML:
string soapEnv =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance" +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<AddList xmlns=\"http://schemas.microsoft.com/sharepoint/soap\">" +
"<listName>" + listName + "</listName>" +
"<description>" + "A Test list" + "</description>" +
"<templateID>100</templateID>" +
"</AddList>" +
"</soap:Body>" +
"</soap:Envelope>";
return soapEnv;
I send this in an http Post with these settings:
uri = "[my sharepoint site]/_vti_bin/lists.asmx";
WebClient client = new WebClient();
client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/";
client.Headers["content-type"] = "text/xml; charset=utf-8";
client.Encoding = Encoding.UTF8;
client.UploadStringCompleted += UploadStringCompleted;
try
{
client.UploadStringAsync(new Uri(uri, UriKind.Absolute), "POST", CAML);
}
catch (Exception ex)
{
MessageBox.Show("Error in upload string async: " + ex.Message);
}
Any ideas? I'm pretty certain it's not an authentication issue since I've used the exact same method in this same program to do the previously mentioned functions. The sharepoint site I'm adding the list to is a test site in which I have full read/write capabilities.
D'oh!
In this part of the soap:Envelope tag: "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance"
I had XMLSchema-instance" instead of XMLSchema\"". I needed that extra parentheses to finish that string...
Related
I have facing issue in displaying German Umlaut characters in HTML page of angular2 application.
My backend services are in java and it returns json String.
This is the response of the post request which is shown in network tab. and it shows ü character properly .
but if i console the data from below snippet, it shows � both in HTML ui and console .
getStackById(project: string, stackId: string, ibsessionid: string) {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
return this.http.post('http://' + this.ip + ':' + this.port + '/IBPublicationBuilder/MiddlewareServlet', 'project=' + project + '&stackid=' + stackId + '&ibsessionid=' + ibsessionid + '&method=getStackById', {
withCredentials: true, headers: headers
}).map(
(res: Response) => {
console.log(res);
return res.json()}
);
}
console:
UI:
Solved the issue with the below solution.
Added
headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
In the header and also Changed the server side.
As I mentioned my services were in java .
Added
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
to my my response object.
I created a search bar that uses the graph API and it worked fine until about a month ago. You could type something into the search bar, and get info back from Facebook related to your search parameter. It stopped working for some reason. So I went to my browsers search bar to type in a graph search manually like this-
http://graph.facebook.com/search?q=zombies
This doesn't work anymore either and I get an error message that says this-
{
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
}
Was there an update that made my search stop working? I've been reading Facebook's documentation and I can't find what I'm looking for. Can someone help me get this working again? My search is located at http://ericnaff.com/html5/p3. Here's my script that I am using-
function searchFB(userSearchparameter) {
$.getJSON('https://graph.facebook.com/search?q=' + userSearchparameter + '&type=post&callback=?', function(fbResults){
$.each(fbResults.data, function() {
// Data Templating
$('<article class="fbResults"></article>').append (
'<section class="resultsSource"><h6 class="shareHeader">' +
'<img class="fromUser" src="https://graph.facebook.com/' + this.from.id + '/picture" height="50" width="50" alt="' + this.from.name + '">' +
'' + this.from.name +' shared a <a class="typeLink" href="' + this.link + '">' + this.
type + '</a> </h6>' +
'<time class="createdTime" datetime="' + this.created_time + '">' + fuzzyFacebookTime(this.created_time.replace(/-/g,'/')) + ' ·</time>' +
'<img class="typeLinkIcon" src="' + this.icon + '" alt="icon"></section>' +
'<section class="resultsDescription"><h6><a class="shareLink" href="' + this.link + '">' +
'<img class="sharePicture" src="' + this.picture + '" height="90" width="90" alt="' + this.from.id + '">' +
'<span class="shareName">' + this.name + '</span>' +
'<span class="shareCaption">' + this.caption + '</span>' +
'<span class="shareDescription">' + this.message + '</span>' +
'</a></h6></section>' +
'<iframe class="linkShare" src="http://facebook.com/plugins/like.php?href=' + this.link + '"></iframe>'
).appendTo('body');
I know it says I don't have the correct access token in my error, but it never used one in the first place and worked fine. If I need to add one, where would I want to include that? Thanks!
You will need an access token; this means an [registered Facebook App][1]
Facebook API changes Jul 10 '13:
Graph API search changes
App access tokens will be required for all search Graph API calls except Places and Pages.
Search for application will no longer be supported.
Create an Facebook developer account
Create a new Facebook App
GET https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=APP_SECRET&grant_type=client_credentials
Append the returned access_token=... to your search requests
Access tokens will also be required for Post searches too:
From Facebook's Developer Roadmap of Completed Changes:
Graph API search changes
User access tokens will be required for all search Graph API calls except Posts, Places
and Pages. App access tokens may also be used for Post search Graph API calls. Places and
Pages search Graph API calls will still require an App access token. Search for Applications
will no longer be supported.
I download the HTML from a webpage:
WebClient client = new WebClient();
DateTime dtStart = DateTime.Now;
string site = "http://www.google.de";
string result = client.DownloadString(site);
DateTime dtEnd = DateTime.Now;
richTests.Text = richTests.Text + result;
webBrowser1.DocumentText = result;
webBrowser1.ScriptErrorsSuppressed = true;
TimeSpan span = dtEnd - dtStart;
WriteLog("Seitenaufruf: " + site);
WriteLog("Time: " + span.Seconds.ToString() + "." + span.Milliseconds.ToString());
Now I have the same code on a internet site with a login validation.
I have a PHPSESSION in my Cookie from Firefox that I can use, so I only need a TextBox for inserting this - the problem here: How to give the WebClient client the PHPSESSION with a cookie - can a WebClient sotre a cookie before sending the DownloadString-Request?
You can read and write headers from the WebClient object. For example:
client.Headers.Add(HttpRequestHeader.Cookie, "cookies");
More info here: http://msdn.microsoft.com/en-us/library/system.net.webclient.headers.aspx
When I query my web service to find a user, if that user is not part of a SharePoint group for the site, the ID is -1.
However, the user CAN get to the site, via a group permission. So my web service call cannot add the user to a "people" box within a list, even though SharePoint itself CAN add it.
My Web service call is as follows:
String searchText = "[My User's Login Name, Spelled Exactly as it appears in SharePoint.]";
String maxresults = "100";
String pType = "All";
String body = "<?xml version=\"1.0\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+ " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>"
+ " <SearchPrincipals "
+ " xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">"
+ " <searchText>" + searchText + "</searchText>"
+ " <maxResults>" + maxResults + "</maxResults>"
+ " <principalType>" + pType + "</principalType>"
+ " </SearchPrincipals>"
+ " </soap:Body>"
+ "</soap:Envelope>";
I get the following response from the web service call:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SearchPrincipalsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SearchPrincipalsResult>
<PrincipalInfo>
<AccountName>[User's Account Name]</AccountName>
<UserInfoID>-1</UserInfoID> <------------ NOTE THE -1 HERE -----------------
<DisplayName>[User's full name, exactly as I sent it in]</DisplayName>
<Email>...</Email>
<Department>...</Department>
<Title>...</Title>
<IsResolved>true</IsResolved>
<PrincipalType>User</PrincipalType>
</PrincipalInfo>
</SearchPrincipalsResult>
</SearchPrincipalsResponse>
</soap:Body>
</soap:Envelope>
If I use this information to add a user to a "people" box, via the web service, The entry becomes "-1;#My User Name", which of course it cannot find, so the List.asmx webservice returns an error of 0x81020054 : The user does not exist or is not unique.
When I add the user to a group within the site directly, their ID resolves out just fine and everything goes through as normal. I remove them from the group and it returns to -1 again.
Any thoughts and/or suggestions for always returning a valid ID?
I can see you are using SearchPrincipals method. Instead try using ResolvePrincipals method.
Documentation here: http://msdn.microsoft.com/en-us/library/people.people.resolveprincipals(v=office.12).aspx
That method has a bool parameter where you can specify that if the user does not belong to the site, then it should be added, this way you will always make sure that you are always getting the ID even if the user does not belong to the site.
PeopleWebService.People pe = new PeopleWebService.People(); //People.asmx web service
string[] users = new string[] { "youruser" };
PeopleWebService.PrincipalInfo[] pInfo = pe.ResolvePrincipals(users, PeopleWebService.SPPrincipalType.User, true); //third param is true
string userID = pInfo[0].UserInfoID.ToString();
I'm using HTTPWebRequest/HTTPWebResponse to interact with the site (www.lockerz.com). So, I authenticate on the site:
HttpWebRequest webRequest = (HttpWebRequest) HttpWebRequest.Create("http://www.lockerz.com/auth/login");
byte[] bytes = Encoding.ASCII.GetBytes("handle=" + textBoxEmail.Text + "&password=" + textBoxPassword.Text);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
webRequest.ContentLength = bytes.Length;
Stream os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
Then I get the response:
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
I'm watching the requests\responses using Charles and it says that in the response there must be cookies, but when I try to make a list of the cookies I get it says that there are no cookies!
foreach(Cookie c in webResponse.Cookies) {
writeToLog("Cookie Name: " + c.Name + " Value: " + c.Value);
cc.Add(c);
}
I've tried adding a CookieContainer but it doesn't work anyway.
This may apply here, I have had this problem with sessions, so I will assume the same for cookies.
You are making a call to: http://www.lockerz.com/auth/login. But if a person goes to a page without the "www." part of the url, then their cookies won't survive being sent to the "www." site, because they are different sites (as far as the cookies are concerned).
I would just make the request to "/auth/login", that way, it won't matter what the user has as the url in their browser.
Hope this works.